Is there any tool that reading the headers prints the name of the dynamic libraries required by a Linux executable to run?
I need it to know if there are some weird dependencies (i.e. not very standard) in a binary that I've just built from the source (it's the Python branch of GDB) or it's mostly statically linked. I think that would be easier than reading the makefiles...
/usr/bin/ldd
is your friend. Usage:Sample output:
readelf -d $executable | grep 'NEEDED'
Can be used if you can't run the executable, e.g. if it was cross compiled, or if you don't trust it:
Example:
Sample ouptut:
Note that libraries can depend on other libraries, so you then need:
Choose one, and repeat:
Sample output:
And so on.
/proc/<pid>/maps
for running processesThis is useful to find all the libraries currently being used by running executables. E.g.:
shows all currently loaded dynamic dependencies of
init
(PID1
):This method also shows libraries opened with
dlopen
, tested with this minimal setup hacked up with asleep(1000)
on Ubuntu 18.04.See also: