In Linux, executable files dynamically link to shared libraries containing common functionality that can be reused across applications. The ldd command allows developers to view these library dependencies for debugging and transparency.
This comprehensive guide will explain what ldd is, why it is useful, and provide clear examples for utilizing this important tool.
Shared Libraries and Dependencies
Shared libraries in Linux contain reusable code and resources that programs can link to at runtime to access common functionality without having to implement everything from scratch.
For example, the stdio library provides input/output functions like printf() that many applications rely on. Libraries are dynamically loaded at runtime as dependencies instead of being fully statically linked into the executable.
What is ldd?
ldd stands for “list dynamic dependencies”. It is a common command line tool used to print the shared libraries required by an executable or library file.
Running ldd on a program will display the list of libraries it depends on, like so:
$ ldd /bin/bash
linux-vdso.so.1 => (0x00007ffea75ed000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fe28117f000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe280f7b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe280bb4000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe2813ff000)
This output shows the primary dependencies of the bash executable – we can see it relies on the tinfo, dl, and c standard libraries.
ldd is useful for debugging issues with missing or incompatible libraries. It provides transparency into what executables rely on under the hood.
Using ldd
The basic syntax for ldd is simple:
ldd [options] executable [executable...]
To demonstrate, we can use ldd on the ls command:
$ ldd /bin/ls
linux-vdso.so.1 => (0x00007ffcfd1fc000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f92da1f6000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f92d9ffd000)
libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f92d9df7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f92d99c0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f92d97a3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f92da3fc000)
Here we see ls relies on libselinux, librt, libacl and other common libraries.
Key ldd Options
ldd has several options to modify the output:
- -v – Print more detailed output including version info
- -u – Print unused direct dependencies
- -d – Perform relocation and show missing dependencies
- -r – Fully resolve dependencies, may be slow
For example, to show unused dependencies of ls:
$ ldd -u /bin/ls
linux-vdso.so.1 => (0x00007ffea5999000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fac6658c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fac661d5000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fac65fba000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (unused)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (unused)
libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (unused)
/lib64/ld-linux-x86-64.so.2 (0x00007fac66694000)
We can see that libdl, librt and libacl are reported as unused, so ls isn‘t actually relying on them.
When ldd is Useful
ldd is most helpful for:
- Debugging issues loading shared libraries in executables
- Checking dependencies when compiling code
- Identifying missing libraries causing “not found” errors
- Understanding relationships between components
- Ensuring compatibility when libraries change
For example, if an executable starts crashing due to an updated dependency, ldd can identify the issue.
Static vs Dynamic Libraries
It‘s worth noting ldd only works with dynamic executable files, not statically linked ones. Static linking embeds the library code directly into the program binary at compile time.
Since static executables do not load external libraries at runtime, ldd cannot report on dependencies that aren‘t present.
Conclusion
The ldd command line tool is invaluable for viewing shared library dependencies in Linux executables and debugging issues. This guide covered the basics of using ldd and its output, but there additional advanced capabilities including script integration.
Take advantage of ldd for better understanding and transparency into your Linux programs and libraries! Let us know in the comments if you have any other questions.


