Discovery of Dynamic library dependency on Mac OS & Linux
Asked Answered
C

4

64

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?

Carriecarrier answered 29/6, 2009 at 8:44 Comment(0)
H
109
  • 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.

Hertel answered 29/6, 2009 at 15:16 Comment(2)
What about static libraries? I tried otool -L but all that does is list a bunch of .o files that are used to build the library.Aindrea
@user3055655: Dynamic library dependencies are created when linking. Because a static archive library has not been linked yet, it would not have any dynamic library dependencies.Hertel
V
12

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.

Vermiculite answered 30/9, 2009 at 22:39 Comment(0)
D
6

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

Dorkus answered 29/6, 2009 at 8:50 Comment(2)
Thank you for the prompt reply! It was as simple as: ldd /path/to/executable_or_dylib and the verbose version: ldd -v /path/to/executable_or_dylibCarriecarrier
It runs perfectly for executables. When I run ldd aDynamicLib.so in Ubuntu 9.04, it says: "not a dynamic executable". How to discover dependencies of a .so file? Thank you in advance!Carriecarrier
S
3

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
Separation answered 8/8, 2020 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.