Discovery of Dynamic library dependency on Mac OS & Linux

WindowsLinuxMacosDependencies

Windows Problem Overview


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?

Windows Solutions


Solution 1 - Windows

  • 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.

Solution 2 - Windows

You can also try MacDependency (https://github.com/kwin/macdependency) which provides an UI replacement for otool on MacOS X. It shows complete dependency trees and the exported symbols as well.

Solution 3 - Windows

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

Solution 4 - Windows

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVietView Question on Stackoverflow
Solution 1 - Windowsmark4oView Answer on Stackoverflow
Solution 2 - WindowsKonradView Answer on Stackoverflow
Solution 3 - WindowschuanView Answer on Stackoverflow
Solution 4 - WindowsValidus OculusView Answer on Stackoverflow