Using ldd Command in Linux

The ldd is a command line tool that prints the shared library dependencies of an executable program or shared library. The ldd command can be useful when wanted to find missing dependencies.

This post presents usage examples of ldd command. Examples have been tested on Ubuntu 20.04 LTS.

1. Print shared library dependencies

Run ldd command and provide an executable program or shared library as argument to display shared library dependencies.

Print dependencies of executable program:

ldd /bin/grep

Output: (0x00007ffd9a372000) => /lib/x86_64-linux-gnu/ (0x00007fa65c056000) => /lib/x86_64-linux-gnu/ (0x00007fa65c050000) => /lib/x86_64-linux-gnu/ (0x00007fa65be5e000) => /lib/x86_64-linux-gnu/ (0x00007fa65be3b000)
/lib64/ (0x00007fa65c105000)

Print dependencies of shared library:

ldd /lib/x86_64-linux-gnu/

Output: (0x00007ffd289e9000) => /lib/x86_64-linux-gnu/ (0x00007f2c9ded0000) => /lib/x86_64-linux-gnu/ (0x00007f2c9dcde000)
/lib64/ (0x00007f2c9df6e000)

2. Print shared library dependencies with details

The -v or --verbose option allows to display shared library dependencies with details, including symbol versioning information.

ldd -v /bin/grep

Output: (0x00007ffeea50b000) => /lib/x86_64-linux-gnu/ (0x00007f3f79dcc000) => /lib/x86_64-linux-gnu/ (0x00007f3f79dc6000) => /lib/x86_64-linux-gnu/ (0x00007f3f79bd4000) => /lib/x86_64-linux-gnu/ (0x00007f3f79bb1000)
/lib64/ (0x00007f3f79e7b000)

Version information:
/bin/grep: (GLIBC_2.14) => /lib/x86_64-linux-gnu/ (GLIBC_2.4) => /lib/x86_64-linux-gnu/ (GLIBC_2.5) => /lib/x86_64-linux-gnu/ (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/ (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/ (GLIBC_2.3) => /lib/x86_64-linux-gnu/
/lib/x86_64-linux-gnu/ (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/

3. Print unused direct dependencies

Use -u or --unused option to print unused direct dependencies. This means that shared library was listed as dependency when building binary but actually doesn’t used in binary.

ldd -u /bin/grep


Unused direct dependencies:

There are some notes for using ldd command.

1. Full path of executable program or shared library is required

The ldd command requires to provide the full path of executable program or shared library.

ldd wget


ldd: ./wget: No such file or directory

We can use whereis command to determine path of the binary, source, and manual page files.

whereis wget


wget: /usr/bin/wget /usr/share/man/man1/wget.1.gz /usr/share/info/

Leave a Comment

Your email address will not be published. Required fields are marked *