The ldd
command is a tool used in Linux systems to print a list of shared libraries that a program or library depends on. Shared libraries are collections of precompiled code that can be used by multiple programs, which can save disk space and memory. When a program or library is executed, it may require certain shared libraries to be present in order to function properly. The ldd
command can be used to identify these dependencies.
Overview
The syntax for the ldd
command is as follows:
ldd [options] file
where file
is the path to the program or library file for which you want to list the dependencies.
For example, to list the shared library dependencies of the ls
command, you can run the following command:
ldd /bin/ls
This will print a list of shared libraries that ls
depends on, along with their paths.
linux-vdso.so.1 (0x00007ffcc5f4c000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f3b2c6a1000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3b2c4b0000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f3b2c23d000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3b2c039000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3b2c8c5000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3b2be1b000)
In this example, ls
depends on several shared libraries, including libselinux.so.1
, libc.so.6
, and libpthread.so.0
.
The ldd
command can be useful for troubleshooting issues with programs or libraries that are failing to run correctly. If a program or library is missing a required shared library, ldd
will indicate which library is missing. This information can be used to install the missing library or to update the program or library to use a different version of the library.
Options
The following table lists the available options for the ldd
command:
Option | Description |
---|---|
-v , --verbose |
Prints additional information, including the version of the ldd command and the architecture of the shared libraries. |
-u , --unused |
Prints a list of unused direct dependencies. |
-r , --function-relocs |
Prints the relocation entries for all functions in the shared libraries. |
-d , --data-relocs |
Prints the relocation entries for all data objects in the shared libraries. |
-u , --unused |
Prints a list of unused direct dependencies. |
-c , --check-libs |
Checks the shared libraries for errors. |
-s , --statistics |
Prints some statistics about the shared libraries. |
-x , --ignore-interpreter |
Ignores the interpreter in the program or library file. |
Troubleshooting tips
If ldd
fails to list the shared library dependencies for a program or library, it may be because the program or library file is not a valid executable or shared library. In this case, check that the file is in the correct format and that it has the correct permissions.
If ldd
lists a shared library as missing, it may be because the library is not installed on the system or because the program or library is using an outdated version of the library. In this case, try installing the missing library or updating the program or library to use a newer version of the library.
Notes
- The
ldd
command only works with dynamically linked programs and libraries. It will not work with statically linked programs and libraries. - The
ldd
command may not be available on all Linux systems. If it is not available, you can try using theobjdump
command instead.