Use it when a program fails with "error while loading shared libraries".
Shared Libraries
Shared libraries (.so) are loaded at runtime by the dynamic linker (ld.so), which searches RPATH, LD_LIBRARY_PATH, the ldconfig cache (/etc/ld.so.conf.d) and default paths.
1. ldd <binary> — not found or wrong path?
2. Library present? find / -name '<lib>*' 2>/dev/null.
3. Add path to /etc/ld.so.conf.d/ and run ldconfig.
4. ldconfig -p | grep <lib> — now in cache?
5. Re-run the program.
program starts → ld.so reads needed sonames → searches RPATH/env/cache/defaults → loads libraries
For Software & Source → Shared Libraries, continue with the first unproven Topic check: Inspect the executable architecture and declared shared-object requirements. If that boundary is healthy, advance to the adjacent check: Resolve the effective loader search path/cache and selected objects in the same runtime environment as the failing process. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
ELF executable → DT_NEEDED/SONAME → loader configuration/cache → search paths/RPATH/RUNPATH → selected .so objects → relocations/symbols → process start → workload
Healthy evidence: the loader selects the intended architecture/version for every required SONAME, relocations/symbols resolve and the program passes the dependent workload
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Inspect the executable architecture and declared shared-object requirements.
- Resolve the effective loader search path/cache and selected objects in the same runtime environment as the failing process.
- Check missing/versioned symbols and environment overrides such as library paths or service-specific environment.
- Repeat the functionality that loads/uses the dependency, not just process startup.
Verification chain. ELF executable → DT_NEEDED/SONAME → loader configuration/cache → search paths/RPATH/RUNPATH → selected .so objects → relocations/symbols → process start → workload
Step 3 Commands Verify boundary
ldd /usr/bin/curl
ldconfig
echo $LD_LIBRARY_PATH
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: wrong search path/cache, stale SONAME symlink, architecture mismatch, missing symbol/version or environment overrides select an unintended object
Step 5 Common mistakes Narrow the fault
- Setting
LD_LIBRARY_PATHglobally.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
For libraries in /usr/local/lib or /opt, add the path to /etc/ld.so.conf.d/<name>.conf and run ldconfig. Avoid global LD_LIBRARY_PATH. Check which library is actually loaded with ldd.
git status / git log --oneline -5— repository stateldd <binary>— shared librariesldconfig -p | grep <lib>— libraries in the linker cachemake --version; gcc --version— build tools
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
A .so file existing on disk does not show the dynamic loader will choose it or that its symbols/ABI satisfy the executable.
In depth
Shared libraries at run time: the dynamic linker
When a program starts, the dynamic linker (ld.so) finds and loads its shared libraries. The ld.so(8) manual page defines the search order for a library named without a slash:
1. DT_RPATH, if present and no DT_RUNPATH is set.
2. LD_LIBRARY_PATH.
3. DT_RUNPATH.
4. /etc/ld.so.cache.
5. The default paths, /lib and /usr/lib (or their 64-bit variants).
The manual also notes that LD_LIBRARY_PATH is ignored in secure-execution mode (for example setuid programs). LD_PRELOAD loads extra libraries first. LD_DEBUG shows the linker's decisions.
Inspecting dependencies safely
| Tool | Notes |
|---|---|
ldd ./program | Full dependency tree; the ldd(1) manual warns never to use it on untrusted executables, because it can run code |
objdump -p ./program | grep NEEDED | Direct dependencies only; safe for untrusted files |
ld.so --list ./program | Every dependency and how it was resolved |
readelf -d ./program | NEEDED, RPATH and RUNPATH entries |
Fixing "cannot open shared object file"
| Situation | Fix |
|---|---|
| A library in a non-standard directory, used by many programs | Add the directory to /etc/ld.so.conf.d/<name>.conf, run ldconfig |
| One application ships its own libraries | Set RUNPATH at build time (-Wl,-rpath,'$ORIGIN/../lib') |
| A quick test | LD_LIBRARY_PATH=/opt/tool/lib ./tool |
| A missing system library | Install the package (dnf provides, apt-file search) |
| Wrong architecture | Install the matching 32-bit or 64-bit library |
Security aspects
| Mechanism | Risk |
|---|---|
LD_PRELOAD | Injects code into a process; ignored for setuid binaries |
/etc/ld.so.preload | Affects every program on the system; a common rootkit technique; normally absent |
| Writable directories in ld.so.conf or RPATH | Library hijacking |
host$ /opt/tool/bin/tool --version
/opt/tool/bin/tool: error while loading shared libraries: libtoolcore.so.2: cannot open shared object file: No such file or directory
host$ objdump -p /opt/tool/bin/tool | grep -E "NEEDED|RUNPATH"
NEEDED libtoolcore.so.2
NEEDED libc.so.6
host$ echo /opt/tool/lib | sudo tee /etc/ld.so.conf.d/tool.conf && sudo ldconfig
host$ ld.so --list /opt/tool/bin/tool 2>/dev/null || /lib64/ld-linux-x86-64.so.2 --list /opt/tool/bin/tool
libtoolcore.so.2 => /opt/tool/lib/libtoolcore.so.2 (0x00007f3a...)
host$ LD_DEBUG=libs /opt/tool/bin/tool --version 2>&1 | grep "trying file" | head -3
host$ ls -l /etc/ld.so.preload 2>/dev/null || echo "no ld.so.preload (expected)"
Reading the example
The tool needs libtoolcore.so.2, which isn't in any searched directory, and the binary has no RUNPATH. Adding /opt/tool/lib to the linker configuration fixes it for all programs. ld.so --list confirms where the library now comes from.
Documented example, not captured output.
How it works at runtime
Shared Libraries is part of Software & Source → Shared Libraries. Shared Libraries covers Linux ELF dynamic linking: DT_NEEDED entries, SONAMEs, loader search order, ld.so cache, RPATH/RUNPATH, architecture and symbol/ABI resolution.
Topic-specific state model. Shared Libraries covers Linux ELF dynamic linking: DT_NEEDED entries, SONAMEs, loader search order, ld.so cache, RPATH/RUNPATH, architecture and symbol/ABI resolution.
Interpretation rule. - Shared object exists ≠ loader selects it.
- ldconfig cache entry ≠ ABI compatibility.
- Program starts ≠ every lazy-loaded path works.
- Same SONAME ≠ identical implementation or behavior.
Quick reference
Shared library resolution order: RPATH/RUNPATH in the binary, LD_LIBRARY_PATH, the cache from /etc/ld.so.conf(.d) built by ldconfig, then default paths (/lib64, /usr/lib64).
ldconfig -p | grep libssl
echo /opt/myapp/lib > /etc/ld.so.conf.d/myapp.conf && ldconfig
LD_DEBUG=libs /opt/myapp/bin/app 2>&1 | head -30
readelf -d /opt/myapp/bin/app | grep -E 'RPATH|RUNPATH'
Error error while loading shared libraries: libX.so.N: cannot open shared object file means the library or the right version is missing from these paths. Avoid global LD_LIBRARY_PATH — it affects every program.
Limits and how it fails
Primary failure point. A .so file existing on disk does not show the dynamic loader will choose it or that its symbols/ABI satisfy the executable.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. Shared Libraries owns runtime dynamic-loader selection and linkage; generic library development belongs to Libraries and package ownership belongs to Package Management.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Software & Source → Shared Libraries. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://git-scm.com/docs · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Shared Libraries operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Shared Libraries.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | Shared Libraries covers Linux ELF dynamic linking: DT_NEEDED entries, SONAMEs, loader search order, ld.so cache, RPATH/RUNPATH, architecture and symbol/ABI resolution. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin exact source/revision or recovery point → verify inputs/consistency → observe copy/build/link result → read back destination/artifact and metadata/dependencies → restore/run in intended environment → repeat original workload + regression check. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | ELF executable → DT_NEEDED/SONAME → loader configuration/cache → search paths/RPATH/RUNPATH → selected .so objects → relocations/symbols → process start → workload | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | A .so file existing on disk does not prove the dynamic loader will choose it or that its symbols/ABI satisfy the executable. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux backup/source evidence can establish this proof path: ELF executable → DT_NEEDED/SONAME → loader configuration/cache → search paths/RPATH/RUNPATH → selected .so objects → relocations/symbols → process start → workload | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove unobserved data, metadata, revisions, dependencies, consumers or time periods. A .so file existing on disk does not prove the dynamic loader will choose it or that its symbols/ABI satisfy the executable. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven backup/source/build boundary, capture adjacent identity/read-back/runtime evidence, make only the demonstrated persistent change, then repeat the original workload plus a regression check. | Continue to the next unresolved boundary while preserving the original test condition. |
Shared Libraries · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | Shared Libraries |
|---|---|
| Topic path | Software & Source → Shared Libraries |
| Runtime state | Shared Libraries covers Linux ELF dynamic linking: DT_NEEDED entries, SONAMEs, loader search order, ld.so cache, RPATH/RUNPATH, architecture and symbol/ABI resolution. |
| Fast checks | - Inspect the executable architecture and declared shared-object requirements. - Resolve the effective loader search path/cache and selected objects in the same runtime environment as the failing process. - Check missing/versioned symbols and environment overrides such as library paths or service-specific environment. - Repeat the functionality that loads/uses the dependency, not just process startup. |
| Verification chain | ELF executable → DT_NEEDED/SONAME → loader configuration/cache → search paths/RPATH/RUNPATH → selected .so objects → relocations/symbols → process start → workload Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. |
| Failure boundary | A .so file existing on disk does not prove the dynamic loader will choose it or that its symbols/ABI satisfy the executable. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |