DEV Community

Cover image for Find library dependencies of a binary file (Linux)
Talles L
Talles L

Posted on

Find library dependencies of a binary file (Linux)

The information that we want is stored on the ELF header of the file. We can analyze that with either objdump or readelf:

$ objdump -p /bin/cat | grep NEEDED
  NEEDED               libc.so.6

$ readelf -d /bin/cat | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
Enter fullscreen mode Exit fullscreen mode

Both outputs libc.so.6. But what about the dependencies of libc? You would have to run the command again in a loop to list all the dependencies.

You can avoid all that work with ldd:

$ ldd /bin/cat
        linux-vdso.so.1 (0x00007ffdb3b54000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1aece58000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f1aed076000)
Enter fullscreen mode Exit fullscreen mode

Not only they have listed the libraries but also gave their paths, nice.

If you are curious about linux-vdso.so.1, here's a Stack Overflow answer on it.

Top comments (0)