Question: We use ldd to find dependencies on Linux platform. Unfortunately, ldd doesn't work on Mac OS X. Which command line tool is equivalent to ldd on Mac OS X?

Answer: For Mac OS X, we can use 'otool' in place of ldd for finding dependencies.

Command: otool -L <file-path>

Here is an example for finding dependencies for pdf2swf.

akash$ otool -L /usr/local/bin/pdf2swf
/opt/local/lib/libmp3lame.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/opt/local/lib/libgif.4.dylib (compatibility version 6.0.0, current version 6.6.0)
/opt/local/lib/libjpeg.8.dylib (compatibility version 9.0.0, current version 9.2.0)
/opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 123.0.0)
/opt/local/lib/libfontconfig.1.dylib (compatibility version 6.0.0, current version 6.4.0)
/opt/local/lib/libfreetype.6.dylib (compatibility version 13.0.0, current version 13.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)

We can also dump all the load commands using "otool -l <file-path>".
(On Linux, we can dump the entire contents of the dynamic section with readelf -d <file-path>.)

For more options, see man page for otool.

Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.