Ldd

From LQWiki
Jump to navigation Jump to search

ldd is a useful command that allows you to view the shared libraries that an executable actually uses. For instance as a simple exercise you can view the shared libraries that 'ls' uses:

tweedleburg:~ # ldd /bin/ls
        librt.so.1 => /lib64/librt.so.1 (0x00002b10e2667000)
        libacl.so.1 => /lib64/libacl.so.1 (0x00002b10e2870000)
        libc.so.6 => /lib64/libc.so.6 (0x00002b10e2a77000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b10e2dbd000)
        /lib64/ld-linux-x86-64.so.2 (0x00002b10e244a000)
        libattr.so.1 => /lib64/libattr.so.1 (0x00002b10e2fd8000)

The real use for this command is when an executable is failing because of a missing dependency.

tweedleburg:~ # ldd /bin/ls | grep "not found"

When ldd is run it will display what the executable is Trying to load, but failing to find. Often paths are set up wrongly on other flavours of unix, or ldconfig needs to be run to update the cache for the dynamic linker ld.so.

If you want to get a list of files that are needed by your executables, read RegExP and use:

ldd /home/kde-devel/kde/bin/ktimetracker | sed "s;.*=> \(/[^S]*\).*;\1;" | sed "s;\(.*\) (.*;\1;" | uniq

See also