Skip to main content

Finding the dependencies of a program

The ldd command prints the shared libraries that a program depends on:

$ ldd /usr/bin/ls
        linux-vdso.so.1 (0x00007ffdddbf4000)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f792668c000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f792649a000)
        libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f792640a000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7926404000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f79266e5000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f79263e1000)

In the above example, the ldd command printed the shared libraries that the ls command uses. Do note that the command prints the exact path location of each library. If a library is missing, then the output is different:

$ ldd printhelloclient
        linux-vdso.so.1 (0x00007fff7149f000)
        libprinthello.so.1 => not found
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8465e75000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f8466075000)

Here we print the dependencies of the printhelloclient executable file. We see that this program depends on the missing shared library libprinthello.so.1.

This only can be used on linux systems. For macos try otools(1).