I have not been able to figure out why my binary is not loading. It is a dylib loaded by MATLAB (MEX-file), and links to quite a few dylibs in different locations. MATLAB tells me it cannot load the MEX-file, but I cannot figure out which of its dependencies it cannot find.
Does anybody have any suggestions for how to debug something like this?
On Linux, ldd
is the perfect tool to debug this problem. People keep saying that otool -L
is the MacOS equivalent to the Linux ldd
, but this is not true. ldd
actually looks for the libraries, and tells you which ones can be found, and where they were found. otool -L
only tells you what libraries are needed to link against. It does not effort to check to see if they are there. It doesn't even tell you where libraries are searched for when they use @rpath
.
otool -l
(lowercase L) gives you a dump of the "load commands", there you can see the LC_RPATH
commands, which establish where @rpath
libraries are searched for. But these have not been able to explain to me which dependency is not found.
greadelf
from MacPorts can be used, as well asnm
: unix.stackexchange.com/a/418357/43390, also relevant to: https://mcmap.net/q/500579/-what-is-the-clang-analogue-of-ldd. – Firecrestotool -L
for a Linux executable, an error was raised "object is not a Mach-O file type.". – Firecrestotool
is for macOS binaries, not Linux ones. The SO answer you link talks aboutotool -L
, which I already mention in the question is not useful in this particular case.readelf
andnm
are useful to see what symbols are in the binary, and serve a similar purpose tootool
with other flags. None of them attempt to replicate theldd
functionality. – Digreadelf
,nm
, andotool
operate similarly to howldd
does. This comment motivated me to read further, and the information I collected does not fit in a comment, so I posted it in an answer to a question that seems closer to what I was searching for: https://mcmap.net/q/500580/-inspect-and-get-binary-from-elf-file-on-macos – Firecrestdylib
, so Mach-O analysis on macOS, and what for Mach-O on macOS is the closest thing toldd
for ELF on Linux. My purpose for commenting was informational, to provide pointers for others that might find this thread while searching for ELF analysis on macOS. – Firecrestotool
, but was actually using theotool
that is part of MacPorts package thecctools
(installed as/opt/local/bin/otool
). Both variants raise an error when given an ELF file, with tiny differences in the error message:/opt/local/bin/otool -L file_name
says "llvm-objdump: error: file_name': object is not a Mach-O file type.", whereas/usr/bin/otool -L
says: "llvm-objdump: 'file_name': Object is not a Mach-O file type.". – Firecrestotool
was intended for the ELF case only. Ifotool
supported ELF files, it might have sufficed for what I was trying to confirm (I was looking for some specific versioned symbols). I did not intend to suggest thatotool
is equivalent toldd
. As you have noted, in general,otool
does not perform the kind of analysis thatldd
does. – Firecrest