ldd — What a Binary Needs Before It Can Start, and When the Answer Is a Lie

ByLinuxtastic

November 29, 2026

Three error messages bring people to this command. error while loading shared libraries: libfoo.so.1: cannot open shared object file — the program is fine, a library it needs is not where the loader looks. version 'GLIBC_2.38' not found — the library is there, but older than the program was built against. And the baffling one, No such file or directory (or, from a current bash, cannot execute: required file not found) for a file that is plainly there and executable, which means the file the kernel could not find is not the program but its interpreter. ldd lists the shared libraries a dynamically linked program needs and where the loader would find each of them, and it answers the first two questions well. On the third it answers confidently and wrongly, which is why this page also covers readelf, objdump, file and ldconfig: between them they give the whole picture, and two of them do it without running anything.

ldd /bin/ls
	linux-vdso.so.1 (0x00007f9f6514d000)
	libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f9f650e5000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9f64e00000)
	libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f9f6504b000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f9f6514f000)

Each line is a library name as recorded in some binary, an arrow to the file the dynamic loader resolved it to, and the address it was mapped at (which changes every run and can be ignored). Two lines have no arrow: linux-vdso.so.1 is a page the kernel maps into every process for fast system calls, not a file; and the last line is the dynamic loader itself, ld-linux-x86-64.so.2, the program that actually loads the others. A name followed by => not found is the library the first error message is about.

$ readelf -d /bin/ls | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libselinux.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

ls itself asks for two libraries; ldd listed three. The third, libpcre2-8, is what libselinux needs, and ldd shows the whole closure — everything that will be mapped when the program starts — while readelf -d (or objdump -p) shows only the NEEDED entries written into the file you name. Both views are useful: the closure tells you what has to be installed; the direct list tells you which library to blame when the closure has a hole in it, because the missing one is NEEDED by something in the chain, and readelf -d on each link finds which.

When ldd lies

Every dynamically linked executable names its own loader, in a header field called PT_INTERP, and the kernel refuses to run the program if that file does not exist — with the error No such file or directory, about a file whose name is not in the message. ldd does not use the binary’s interpreter; it runs the system’s own loader against the file, so it prints a clean library list for a program that cannot start. Measured, with a copy of a working program whose interpreter path was altered by one character:

$ ./prog-badinterp
bash: ./prog-badinterp: cannot execute: required file not found
$ ldd ./prog-badinterp
	linux-vdso.so.1 (0x00007f8b667c4000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8b66400000)
	/lib64/ld-linux-x86-65.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f8b667c6000)
$ readelf -l ./prog-badinterp | grep interpreter
      [Requesting program interpreter: /lib64/ld-linux-x86-65.so.2]
$ file ./prog-badinterp
./prog-badinterp: ELF 64-bit LSB pie executable, x86-64, ... dynamically linked, interpreter /lib64/ld-linux-x86-65.so.2, ...

The only hint in the ldd output is the last line, where a name that does not exist is quietly resolved to the real loader. When an executable that exists says “No such file or directory”, read its interpreter with file or readelf -l and check that path exists. In practice it is one of three things: a 32-bit program on a 64-bit system with no 32-bit loader installed (/lib/ld-linux.so.2), a binary built against musl — from Alpine, or a Go or Rust toolchain targeting it — run on a glibc system (/lib/ld-musl-x86_64.so.1), or a binary for another architecture entirely. The same error, from the same cause, comes from a script whose #! line names an interpreter that is not there, including one with a Windows carriage return on the end of it.

The ldd manual carries a second warning: do not run it on an executable you do not trust, because historically it ran the program’s own interpreter with a tracing variable set, and a hostile interpreter could ignore the variable and do as it liked. Measured on glibc 2.39, with a binary whose PT_INTERP pointed at a program of our own: ldd ran the system loader instead and the planted program never executed, and a library constructor was not run either, because the loader in trace mode does not run initialisers. That is the current behaviour, not a guarantee, and objdump -p FILE | grep NEEDED and readelf -d FILE read the headers without loading anything at all. Use them on anything you downloaded.

The toolkit

CommandTells you
ldd FILEEvery library the program will map, resolved as the loader would resolve them now; not found for the missing ones
ldd -v FILEThe same plus the symbol versions each library must provide (GLIBC_2.34 and so on)
ldd -u FILEDirect dependencies that are linked but never used — an over-linked build
readelf -d FILEThe dynamic section: NEEDED entries, RUNPATH/RPATH, SONAME; reads the file, runs nothing
readelf -l FILEProgram headers, including Requesting program interpreter:
objdump -p FILENEEDED and the rest in another layout; objdump -T FILE lists the dynamic symbols with their versions
file FILEArchitecture, static or dynamic, the interpreter path, stripped or not — the first thing to run on a mystery binary
ldconfig -pWhat is in the loader’s cache: every library it will find by name without a path
ldconfigRebuild that cache from /etc/ld.so.conf, /etc/ld.so.conf.d/*.conf and the trusted directories (root)
LD_DEBUG=libs PROGThe loader narrating every directory it tries, in order; LD_DEBUG=help lists the other channels
/lib64/ld-linux-x86-64.so.2 --list FILEWhat ldd does, called directly
strace -e openat PROGThe same search as the kernel saw it: one failed openat per directory

“cannot open shared object file”: where the loader looks

$ ./prog
./prog: error while loading shared libraries: libhello.so.1: cannot open shared object file: No such file or directory
$ ldd ./prog | grep hello
	libhello.so.1 => not found
$ LD_DEBUG=libs ./prog 2>&1 | head -4
       858:	find library=libhello.so.1 [0]; searching
       858:	 search cache=/etc/ld.so.cache
       858:	 search path=/lib/x86_64-linux-gnu/glibc-hwcaps/x86-64-v4:...:/lib/x86_64-linux-gnu:...:/usr/lib		(system search path)
       858:	  trying file=/lib/x86_64-linux-gnu/glibc-hwcaps/x86-64-v4/libhello.so.1

The loader looks, in order, in the directories named by the binary’s RPATH (if it has one, an older mechanism), then LD_LIBRARY_PATH from the environment, then the binary’s RUNPATH, then the cache /etc/ld.so.cache, then the built-in directories /lib and /usr/lib with the architecture subdirectory. LD_DEBUG=libs prints exactly that walk for the library it cannot find, which is faster than reasoning about it. The three fixes correspond to three of those places, and the right one depends on who owns the library:

$ LD_LIBRARY_PATH=$PWD/lib ./prog; echo "rc=$?"          # 1. the environment: for this run
rc=42
$ sudo cp lib/libhello.so.1 /usr/local/lib/ && ./prog   # 2. a system directory...
./prog: error while loading shared libraries: libhello.so.1: cannot open shared object file: No such file or directory
$ sudo ldconfig && ldconfig -p | grep hello && ./prog; echo "rc=$?"   # ...plus the cache rebuild
	libhello.so.1 (libc6,x86-64) => /usr/local/lib/libhello.so.1
rc=42
$ gcc -o prog prog.c -Llib -lhello -Wl,-rpath,'$ORIGIN/lib'   # 3. a RUNPATH baked in at build time
$ readelf -d prog | grep RUNPATH
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/lib]

The middle one is the step people miss: copying a library into /usr/local/lib changes nothing until ldconfig has rebuilt the cache, because the loader consults the cache, not the directory. Package managers run ldconfig for you, which is why libraries installed with apt or dnf just work and the one you built from source does not. LD_LIBRARY_PATH is for testing and for a wrapper script that sets it for one program; set globally in a profile it makes every program on the machine search your directory first, which is how one stray libssl.so breaks ssh. RUNPATH with $ORIGIN — “the directory this binary is in” — is how relocatable software ships its own libraries alongside itself, and it is what you are looking at when readelf -d on a vendor’s program shows a path you did not create. The Life of a Package is the page on how a distribution keeps all of this consistent; How Packages and Dependencies Work is why “depends on libfoo1” means a SONAME, not a file name.

“version GLIBC_2.38 not found”

$ objdump -T /bin/ls | grep -o 'GLIBC_2\.[0-9.]*' | sort -Vu | tail -1
GLIBC_2.38
$ ldd --version | head -1
ldd (Ubuntu GLIBC 2.39-0ubuntu8.12) 2.39

glibc keeps old versions of every symbol it has ever changed, which is why a program built ten years ago still runs today; the reverse is not true. A binary built on a newer system records the newest symbol version it used, and an older glibc that has never heard of GLIBC_2.38 refuses to load it, naming the version in the error. The first line above finds the newest version a binary requires; the second is what this machine provides. There is no fix on the running machine short of upgrading its glibc, which means upgrading the distribution. The fix is on the build side: build on the oldest system you intend to support, build in a container of that system, or link statically. The same message with another library’s name (GLIBCXX_3.4.32 for the C++ runtime, OPENSSL_3.0.0) has the same cause and the same answer.

“not a dynamic executable”

$ ldd /sbin/ldconfig
	not a dynamic executable
$ file -L /sbin/ldconfig
/sbin/ldconfig: POSIX shell script, ASCII text executable

ldd says this about three different things: a statically linked program, which needs no libraries and will run anywhere with the right kernel; a file that is not an ELF executable at all, such as a script (on Ubuntu /sbin/ldconfig is a shell wrapper around the real binary, as above); and a binary for another architecture, which the loader cannot examine. file distinguishes all three in one line. Static binaries are increasingly common — Go produces them by default, Rust can, and container images built FROM scratch contain nothing else — and for those every question on this page has the same short answer. What Ships in Your Container Image is where the static-versus-musl-versus-glibc choice is made in practice.

Common problems

SymptomCauseCheck / fix
cannot open shared object fileLibrary not in any searched directory, or not in the cacheldd for the name; ldconfig -p | grep NAME; install the package, or ldconfig after a manual copy
Library file is present and it still cannot open itCache not rebuilt; or a 32-bit library for a 64-bit program (or vice versa); or wrong SONAME (libfoo.so present, libfoo.so.1 wanted)ldconfig; file on the library; readelf -d LIB | grep SONAME
No such file or directory for an executable that existsIts interpreter is missing: 32-bit loader, musl, other architecture, or a bad #! linefile PROG; check the interpreter path exists; head -1 script | cat -A for ^M
version GLIBC_2.xx not foundBinary built against a newer glibcobjdump -T for the required version; rebuild on an older base
Works for root, fails for a user (or in cron)LD_LIBRARY_PATH set in one environment only; or a RUNPATH directory the user cannot readLD_DEBUG=libs as the failing user; put the library in a cached directory instead
Wrong version of a library is loadedLD_LIBRARY_PATH or an RPATH pointing at an old copyldd shows which file won; LD_DEBUG=libs shows why
ldd output differs between two usersLD_LIBRARY_PATH differs; ldd honours the environment it runs inenv -i ldd PROG for a clean view
Program loads but crashes at start with a symbol lookup errorA library satisfies the SONAME but is the wrong build; mixed library setsldd -v; LD_DEBUG=symbols,bindings
Setuid program ignores LD_LIBRARY_PATHBy design: the loader drops it and LD_PRELOAD for privileged binariesInstall the library properly

Quick reference

ldd PROG                                  # libraries it will load, and the missing ones
ldd -v PROG                               # ...with the symbol versions required
readelf -d PROG | grep -E 'NEEDED|RUNPATH'  # direct dependencies and baked-in search path
readelf -l PROG | grep interpreter        # the loader it asks for (must exist)
file PROG                                 # arch, static/dynamic, interpreter, in one line
objdump -p PROG | grep NEEDED             # dependencies without running anything (untrusted files)
objdump -T PROG | grep -o 'GLIBC_2\.[0-9.]*' | sort -Vu | tail -1   # newest glibc it needs
ldd --version                             # the glibc this machine has
ldconfig -p | grep NAME                   # is the library in the cache?
sudo ldconfig                             # rebuild the cache after copying a library in
LD_DEBUG=libs PROG 2>&1 | less             # every directory tried, in order
LD_LIBRARY_PATH=/path PROG                # for one run or one wrapper, never a profile
strace -e trace=openat PROG 2>&1 | grep NAME   # the same search, from the kernel's side

Related reading