Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacOSX: which dynamic libraries linked by binary?

Tags:

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.

like image 544
Cris Luengo Avatar asked Aug 02 '17 15:08

Cris Luengo


People also ask

Where is Binary on Mac?

the shell looks first in /bin , then in /sbin and so on, until it finds program , then it runs that. So, if you want to install a binary (or program, or script) just put it anywhere on your PATH.

Where are Dylib files on Mac?

Where do DYLIB files go on a Mac? The standard locations for dynamic libraries are ~/lib, /usr/local/lib, and /usr/lib.

What is LDD on Mac?

ldd uses ld to load executable files, and recursively loads dynamically-linked libraries. So using ldd requires being on the target system (e.g., Linux). Thus, ldd cannot be used for ELF files on macOS.

Where do I put Dylib files?

/usr/local/lib.


1 Answers

Try setting these environment variables before running matlab:

export DYLD_PRINT_LIBRARIES=1 export DYLD_PRINT_LIBRARIES_POST_LAUNCH=1 export DYLD_PRINT_RPATHS=1 

Run man dyld for more possibilities.

You can also set the variables for just the matlab command like this:

DYLD_PRINT_LIBRARIES=1 DYLD_PRINT_LIBRARIES_POST_LAUNCH=1 DYLD_PRINT_RPATHS=1 matlab 
like image 92
rob mayoff Avatar answered Sep 26 '22 01:09

rob mayoff