13

How do I find out what DLLs an executable depends on?

On systems with the GNU development toolchain (gcc &c) I use ldd for that, but what about the clang systems, like, e.g., Mac OS X (which does not have ldd)?

sds
  • 58,617
  • 29
  • 161
  • 278
  • Have you tried `ldd` ? The OS must be able to figure out the libraries needed, so `clang` and `gcc` mustdo pretty much the same thing. – MSalters May 16 '14 at 14:49
  • @MSalters: macosx does not have `ldd` – sds May 16 '14 at 15:03
  • 1
    Eh, it's apparently `otool -L`. The point I failed to make was that the compiler doesn't matter (there's a gcc port for MacOSX) – MSalters May 16 '14 at 15:09
  • @MSalters: please turn your comment into an answer so that I can accept it and close the question. Thanks! – sds May 16 '14 at 15:12

2 Answers2

11

On Mac OSX, you'd use otool -L instead of ldd. This works regardless of the compiler you used. Other operating systems may have yet other tools; e.g. on Windows you'd use Dependency Walker.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • 1
    Also, for inspecting Linux binaries on a macOS, `greadelf` from MacPorts can be used, as well as `nm`: https://unix.stackexchange.com/a/418357/43390, also relevant to: https://stackoverflow.com/q/45464584/1959808. When trying `otool -L` for a Linux executable, an error was raised "object is not a Mach-O file type.". – 0 _ May 29 '21 at 21:00
5

llvm-readelf ---needed-libs is the clang analogue of ldd. Here's is the official documentation

~/weechat $ llvm-readelf --needed-libs bin/weechat
NeededLibraries [
  libc.so
  libcurl.so
  libdl.so
  libgcrypt.so
  libgnutls.so
  libgpg-error.so
  libiconv.so
  libm.so
  libncursesw.so.6
]
Arun
  • 183
  • 2
  • 9
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 17 '21 at 06:37