Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find which shared library is loaded by a process on OSX? [closed]

I am trying to compile and use a shared C library as a python module and I am observing that depending on the DYLD_LIBRARY_PATH my code works or it crashes with a cryptic error message.

Jul 24 02:44:44 master 
$ DYLD_LIBRARY_PATH=/opt/local/lib  python -c 'import opengm' 
OKAY

Jul 24 02:45:41 master 
$ DYLD_LIBRARY_PATH= python -c 'import opengm' 
python(86214,0x7fff70ccdcc0) malloc: *** error for object 0x7fff70177500: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap

I have tried to manually inspect which libraries are common between /usr/lib and /usr/local/lib and /opt/local/lib but I have not been able to find the cause of the crash. One way to figure out the cause of the problem will be to figure out which dylib files do the two processes use? I was not able to figure this using opensnoop or dtruss but maybe I was using those tools wrong.

How can I figure out the cause of this crash?

like image 597
Pushpendre Avatar asked Jul 24 '16 06:07

Pushpendre


1 Answers

You can set DYLD_PRINT_LIBRARIES=YES in the environment to have dyld print every dynamic library that it loads into the process:

$ DYLD_PRINT_LIBRARIES=YES /usr/bin/true 
dyld: loaded: /usr/bin/true
dyld: loaded: /usr/lib/libSystem.B.dylib
[ ... snip ... ]
dyld: loaded: /usr/lib/libc++.1.dylib
dyld: loaded: /usr/lib/libDiagnosticMessagesClient.dylib
$
like image 116
bdash Avatar answered Nov 10 '22 17:11

bdash