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

1

8

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?

Yawning answered 24/7, 2016 at 6:56 Comment(2)
I'm voting to close this question as off-topic because it has been cross-posted on a better suited Stack Exchange site. In future, please only post your question on a single Stack Exchange site. For more information, see here. (apple.stackexchange.com/questions/247227/…).Delozier
This question seems totally on topic to me (suppose you want to debug you compilation configuration). However it is a duplicate of #2185275Thora
W
13

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
$
Wheen answered 26/7, 2016 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.