Introduction / Why This Is Needed
The ldd (List Dynamic Dependencies) utility is a standard Linux tool for viewing the dynamic dependencies of an executable file. It shows which shared libraries (.so files) need to be loaded when the program starts. This is essential for:
- Diagnosing errors like
error while loading shared libraries: libXYZ.so: cannot open shared object file. - Understanding which packages need to be installed on a clean system.
- Verifying binary integrity and detecting potential issues with
RPATH/RUNPATH.
After completing this guide, you will be able to quickly locate and resolve missing library issues.
Requirements / Preparation
Before you begin, ensure that:
- You have access to a Linux terminal (Ubuntu, CentOS, Fedora, Debian, etc.).
- The
lddutility is installed. It is typically included in thelibc6(Debian/Ubuntu) orglibc(RHEL/CentOS) packages. You can verify with:ldd --version - You have an executable file (in ELF format) to analyze. This can be any binary on your system, such as
/usr/bin/lsor your own compiled file. - You have read permissions for the file. If the file belongs to another user, use
sudoor copy it to your directory.
Step-by-Step Instructions
Step 1: Basic ldd Execution
Simply specify the path to the executable:
ldd /bin/ls
Example output:
linux-vdso.so.1 (0x00007ffd6d7f9000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f8c1a400000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8c19e00000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f8c19a00000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8c1a800000)
Each line contains:
- The library name (e.g.,
libc.so.6). - The
=>arrow and the full path where the library will be loaded. - The memory address (in parentheses), if the library is already loaded in the current process (may vary per run).
Step 2: Interpreting Key Elements
linux-vdso.so.1— a virtual dynamic library provided by the kernel (not a real file on disk)./lib64/ld-linux-x86-64.so.2— the dynamic loader (interpreter); the program will not run without it.- If
not foundappears instead of a path, the library is missing from standard search paths (/lib,/usr/lib,LD_LIBRARY_PATH).
Step 3: Handling Missing Libraries
If your output contains lines like libsomething.so => not found, do the following:
- Find the package containing the library. For Debian/Ubuntu:
apt-file search libsomething.so
Ifapt-fileis not installed, first install it:sudo apt update && sudo apt install apt-file && sudo apt-file update.
For RHEL/CentOS/Fedora:yum provides */libsomething.so
ordnf provides */libsomething.so - Install the found package:
sudo apt install package_name # Debian/Ubuntu sudo yum install package_name # RHEL/CentOS - Update the library cache:
sudo ldconfig - Re-check the file with
ldd.
Step 4: Using Options for Advanced Analysis
-v(verbose) — shows all library matches, including duplicates and versions.ldd -v /usr/bin/ssh-u— lists unused direct dependencies (useful for cleaning upDT_NEEDEDin the ELF header).ldd -u /usr/bin/ssh--version— displays thelddutility version.
Step 5: Security and Alternatives
⚠️ Important: Running
lddon untrusted executables can be dangerous! Some binaries may execute code viaDT_RPATH/DT_RUNPATH. For security, use instead:objdump -p /path/to/file | grep NEEDEDor
readelf -d /path/to/file | grep NEEDEDThese commands only read the ELF header and do not execute any code.
Verifying the Result
A successful outcome:
- The
lddoutput contains nonot foundlines. - All libraries have full paths.
- The dynamic loader (
ld-linux.so) is correctly listed.
If you installed missing libraries, restart the program to confirm it runs without errors.
Potential Issues
| Problem | Symptoms | Solution |
|---|---|---|
| Library not found | libXYZ.so => not found | Install the package containing the library and run sudo ldconfig. |
| Wrong architecture | ldd: /path/file: failed to load module: invalid ELF header | The file is compiled for a different architecture (e.g., 32-bit on a 64-bit system). Install compatible libraries (e.g., libc6-i386). |
| Static binary | statically linked in output | Libraries are embedded in the file. No dependencies exist; ldd is not applicable. |
| No read permissions | ldd: /path/file: Permission denied | Add permissions: chmod +r /path/file or use sudo ldd /path/file (with caution!). |
Outdated ldd version | Unexpected output format or errors | Update the libc6/glibc package: sudo apt upgrade libc6 or sudo yum update glibc. |
If the issue persists, check the LD_LIBRARY_PATH and LD_DEBUG environment variables for detailed library loading diagnostics.