Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Shared Libraries

Direct answer

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.

When to use this

Use it when a program fails with "error while loading shared libraries".

First 30 seconds

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.

Operational verification

program starts → ld.so reads needed sonames → searches RPATH/env/cache/defaults → loads libraries

Evidence · next step

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
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when a program fails with "error while loading shared libraries".
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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_PATH globally.
Evidence references

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.

observation · 1
Key points

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.

Key checks
  • git status / git log --oneline -5 — repository state
  • ldd <binary> — shared libraries
  • ldconfig -p | grep <lib> — libraries in the linker cache
  • make --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

ToolNotes
ldd ./programFull dependency tree; the ldd(1) manual warns never to use it on untrusted executables, because it can run code
objdump -p ./program | grep NEEDEDDirect dependencies only; safe for untrusted files
ld.so --list ./programEvery dependency and how it was resolved
readelf -d ./programNEEDED, RPATH and RUNPATH entries

Fixing "cannot open shared object file"

SituationFix
A library in a non-standard directory, used by many programsAdd the directory to /etc/ld.so.conf.d/<name>.conf, run ldconfig
One application ships its own librariesSet RUNPATH at build time (-Wl,-rpath,'$ORIGIN/../lib')
A quick testLD_LIBRARY_PATH=/opt/tool/lib ./tool
A missing system libraryInstall the package (dnf provides, apt-file search)
Wrong architectureInstall the matching 32-bit or 64-bit library

Security aspects

MechanismRisk
LD_PRELOADInjects code into a process; ignored for setuid binaries
/etc/ld.so.preloadAffects every program on the system; a common rootkit technique; normally absent
Writable directories in ld.so.conf or RPATHLibrary 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
linux shared librariesld.so shared objectelf dynamic linking
Embedded reference data

Quick lookup tables

Shared Libraries operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Shared Libraries.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateShared 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 verificationPin 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 chainELF executable → DT_NEEDED/SONAME → loader configuration/cache → search paths/RPATH/RUNPATH → selected .so objects → relocations/symbols → process start → workloadTrace requested/configured state through effective state to the observed workload result.
Failure boundaryA .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 evidenceCorrelated 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 → workloadUse this observation only for the specific claim it actually supports.
Evidence limitIt 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 checkContinue 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 boundaryShared Libraries
Topic pathSoftware & Source → Shared Libraries
Runtime stateShared 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 chainELF 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 boundaryA .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 ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?