HHHHq ~ “Hack”

A blog about programming and…

otool: OS X equivalent of ‘ldd’

without comments

I rarely do C++ development anymore, but today I had to dig around in some of our C++ code; I’m modifying the build to produce some new artifacts.  I work primarily on a Mac and secondarily on Linux.  Those familiar with Linux development tools probably know about ldd — it’s a simple tool that displays the shared libraries a given executable (or other library) depends on.  I was wondering if OS X had an equivalent… and it does: otool.  otool does a bit more than ldd, but if you just want to print dependencies like ldd does then try: otool -L file . For instance,

me@hubble:~$ otool -L /bin/bash
/bin/bash:
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

And on Linux, using ldd, you get:

me@galileo:~$ ldd /bin/bash
	linux-gate.so.1 =>  (0xb8095000)
	libncurses.so.5 => /lib/libncurses.so.5 (0xb8052000)
	libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb804e000)
	libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7eea000)
	/lib/ld-linux.so.2 (0xb8096000)

For a list of other under-used OS X command line tools, check out Mac OS X Hacking Tools.

Written by James Royalty

June 1st, 2009 at 1:30 pm

Posted in Programming

Tagged with , , ,