Find libraries a binary was linked against

41

10

I know that there is a command that lists me the libs and respective versions a software was linked against.

Something with ld or libtool?

But I just cannot remember. Spent some time on google but didn't come up with anything useful.

Update
ldd <binary> would help on linux, (from @Ernelli) while I found that otool -L <binary> does something similar on MacOS X.

er4z0r

Posted 2011-01-30T14:35:10.670

Reputation: 631

http://stackoverflow.com/questions/50159/show-all-libraries-used-by-executables-on-linux – Ciro Santilli 新疆改造中心法轮功六四事件 – 2016-09-04T13:39:44.393

Answers

45

Try ldd binary-exec

Example:

~$ ldd /bin/bash
    linux-gate.so.1 =>  (0x00606000)
    libncurses.so.5 => /lib/libncurses.so.5 (0x00943000)
    libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00c5d000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x003e9000)
    /lib/ld-linux.so.2 (0x00a41000)

Ernelli

Posted 2011-01-30T14:35:10.670

Reputation: 742

Dang! So my first try was right. Just need to install it on my Mac so it acutally knows the command ;-) – er4z0r – 2011-01-30T15:45:21.640

@er4z0r: FYI, Mac OS is BSD, not Linux. – user1686 – 2011-01-30T19:17:22.953

6grwaity: you are right. While ldd would help on linux I found that 'otool -L <binary>' does something similar. – er4z0r – 2011-01-30T20:56:33.987

15

To find what it directly needs:

readelf -d APP | grep NEEDED

ldd as mentioned elsewhere will show all direct and indirect libs - everything it needs at runtime. This may not be a complete list, since you may dynamically open things with dlopen(), but this should work 99% of the time.

ld and libtool are used at compile/link time. They aren't useful once you have an app.

EDIT I can see by later answers you were asking about OSX, but I want to add to my answer on Linux tools:

One thing I forgot to mention, quite a while ago; you asked about versions. Neither ldd nor readelf will answer the "what version" question. They will tell you the filename of the library you are looking for, and the naming convention may have some version info, but nothing enforces this. Symbols may be versioned, and you would have to much about even lower level with nm to see these,

Rich Homolka

Posted 2011-01-30T14:35:10.670

Reputation: 27 121

9

Another way would be to use objdump.

objdump -x "binary" | grep NEEDED

This shows all needed dependencies only for this binary. Very useful.

Pranav

Posted 2011-01-30T14:35:10.670

Reputation: 91