Discovery of Dynamic library dependency on Mac OS & Linux

Viewed 31071

On Windows there is a tool Depends.exe to discover dependency of an EXE/DLL file on other DDLs. Which commandline tool is equivalent on Mac OS and Linux?

4 Answers
  • Mac OS X: otool -L file
  • Linux: ldd file

If those commands don't provide what you want, on Mac OS X you can dump all the load commands with otool -l file. On Linux you can dump the entire contents of the dynamic section with readelf -d file.

try ldd in the terminal. This will provide you a list of dynamic libraries that the binary needs.

You can put something like following into your bashrc so that you can always use "ldd" as interface but it will redirect macos equivalent one if machine is mac.

# Macos equivalent of ldd
if [[ "$OSTYPE" =~ "darwin"* ]]
then
  alias ldd="otool -L"
fi
Related