Using the "ldd" Command in Linux

The ldd command can be used to show you the shared libraries required by any given program.

This is useful for working out when there is a missing dependency and can be used to list missing functions and objects.

ldd Command Syntax

This is the proper syntax when using the ldd command:

ldd [OPTION]... FILE...

Here are the available ldd command switches that can be inserted into the [OPTION] spot in the above command:

 --help print this help and exit
--version print version information and exit
-d, --data-relocs process data relocations
-r, --function-relocs process data and function relocations
-u, --unused print unused direct dependencies
-v, --verbose print all information

How to Use the ldd Command

You can use the following command to get more information from any ldd command:

ldd -v /path/to/program/executable

The output shows version information as well as the paths and addresses to the shared libraries, like this:

ldd => (0x00007fff26ac8000) => /lib/ 0x00007ff1df55a000)
/lib64/ (0x00007ff1dfafe000)

If the SO file doesn't exist at all, you can find the missing libraries using the following command:

ldd -d path/to/program

The output is similar to the following: (0x00007ffc2936b000)
/home/gary/demo/ => not => usr/lib/ (0x00007fd0c6259000)
/lib64/ (0x00007fd0c65fd000)

Important: Never run the ldd command against an untrusted program since the command might actually execute it. This is a safer alternative that shows just the direct dependencies and not the whole dependency tree: objdump -p /path/to/program | grep NEEDED.

How to Find the Path to an Application

You have to provide the full path to an application if you want to find its dependencies with ldd, which you can do a number of ways.

For example, this is how you'd find the path to Firefox:

find / -name firefox

The problem with the find command, however, is that it will not only list the executable but everywhere that Firefox is located, like this:

  • /etc/skel/.mozilla/firefox
  • /home//cache/mozilla/firefox
  • /home//.mozilla/firefox
  • /usr/bin/Firefox
  • /usr/lib/Firefox
  • /usr/lib/Firefox/Firefox

This approach is a bit of an overkill and you may need to use the sudo command to elevate your privileges, else you're likely to get lots of permission denied errors.

It's instead much easier to use the whereis command to find an application's path:

whereis firefox

This time the output might look like this:




All you have to do now to find the shared libraries for Firefox is type the following command:

ldd /usr/bin/firefox

The output from the command will be something like this: (0x00007ffff8364000) => /usr/lib/ (0x00007feb9917a000) => /usr/lib/ (0x00007feb98f76000) => /usr/lib/ (0x00007feb98bf4000) => /usr/lib/ (0x00007feb988f6000) => /usr/lib/ (0x00007feb986e0000) => /usr/lib/ (0x00007feb9833c000)
/lib64/ (0x00007feb99397000)

The is the name of the library and the hex number is the address where the library will be loaded to in memory.

You'll notice on many of the other lines that the => symbol is followed by a path. This is the path to the physical binary; the hex number is the address where the library will be loaded.