What is the clang analogue of ldd?
Asked Answered
M

2

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)?

Muriate answered 16/5, 2014 at 14:19 Comment(4)
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.Concerted
@MSalters: macosx does not have lddMuriate
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)Concerted
@MSalters: please turn your comment into an answer so that I can accept it and close the question. Thanks!Muriate
C
12

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.

Concerted answered 16/5, 2014 at 15:13 Comment(1)
Also, for inspecting Linux binaries on a macOS, greadelf from MacPorts can be used, as well as nm: unix.stackexchange.com/a/418357/43390, also relevant to: https://mcmap.net/q/475972/-macosx-which-dynamic-libraries-linked-by-binary/1959808. When trying otool -L for a Linux executable, an error was raised "object is not a Mach-O file type.".Sansone
P
7

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
]
Peptidase answered 17/11, 2021 at 6:34 Comment(1)
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.Connors

© 2022 - 2024 — McMap. All rights reserved.