How can I easily find out the direct shared object dependencies of a Linux binary in ELF format?
I'm aware of the ldd tool, but that appears to output all dependencies of a binary, including the dependencies of any shared objects that binary is dependent on.
You can use
readelf
to explore the ELF headers.readelf -d
will list the direct dependencies asNEEDED
sections.If you want to find dependencies recursively (including dependencies of dependencies, dependencies of dependencies of dependencies and so on)…
You may use
ldd
command. ldd - print shared library dependenciesThe objdump tool can tell you this information. If you invoke objdump with the -x option, to get it to output all headers then you'll find the shared object dependencies right at the start in the "Dynamic Section".
For example running 'objdump -x /usr/lib/libXpm.so.4' on my system gives the following information in the "Dynamic Section":
The direct shared object dependencies are listing as 'NEEDED' values. So in the example above, libXpm.so.4 on my system just needs libX11.so.6 and libc.so.6.
It's important to note that this doesn't mean that all the symbols needed by the binary being passed to objdump will be present in the libraries, but it does at least show what libraries the loader will try to load when loading the binary.
ldd -v prints the dependency tree under "Version information:' section. The first block in that section are the direct dependencies of the binary.
See Hierarchical ldd(1)