Mastering ldd: How to List Shared Library Dependencies on Linux
This guide explains the ldd command, its underlying environment variables, available options, and practical examples, showing how to safely display a program's shared library dependencies without executing the program itself.
1. Command Overview
The ldd command prints the list of shared libraries required by an executable or shared object file. It is not a compiled binary but a shell script that invokes the dynamic loader ( ld-linux.so) with specific environment variables.
2. Relevant Environment Variables
Key variables that affect ldd behavior are: LD_TRACE_LOADED_OBJECTS=1 (enabled by default)
LD_WARNLD_BIND_NOWLD_LIBRARY_VERSIONLD_VERBOSELD_DEBUGOnly LD_TRACE_LOADED_OBJECTS is required for normal operation; the others are optional.
3. Mapping Options to Variables
-d, --data-relocs→
LD_WARN=yes-r, --function-relocs→ LD_WARN=yes and
LD_BIND_NOW=yes-u, --unused→
LD_DEBUG="unused"-v, --verbose→
LD_VERBOSE=yes4. Using LD_TRACE_LOADED_OBJECTS Directly
Setting LD_TRACE_LOADED_OBJECTS to a non‑empty value forces the dynamic loader to list dependencies without actually running the target program. export LD_TRACE_LOADED_OBJECTS=1 Running a command such as ls after exporting this variable will display the libraries that ls depends on, e.g.:
linux-vdso.so.1 => (0x00007ffd1d3cf000)</code>
<code>/lib64/libc.so.6 => /lib64/libc.so.6 (0x00007fbbe665e000)</code>
<code>/lib64/ld-linux-x86-64.so.2 (0x00007fbbe7053000)Unsetting the variable restores normal command behavior:
unset LD_TRACE_LOADED_OBJECTS5. Command Syntax
ldd [OPTIONS] <FILES>[OPTIONS]are optional; <FILES> is a required list of executables or shared objects.
6. Common Options
--version: show ldd version -v, --verbose: detailed mode, print all related information -u, --unused: list unused direct dependencies -d, --data-relocs: perform relocations and report missing objects -r, --function-relocs: perform data and function relocations (ELF only) --help: display help
7. Example Usage
Display the shared libraries required by /usr/bin/ls:
ldd /usr/bin/ls</code>
<code>linux-vdso.so.1 => (0x00007ffd90514000)</code>
<code>/lib64/libc.so.6 => /lib64/libc.so.6 (0x00007f294a2e4000)</code>
<code>/lib64/ld-linux-x86-64.so.2 (0x00007f294acd9000)These examples demonstrate that ldd works by configuring the dynamic loader via environment variables, allowing safe inspection of binary dependencies.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
