141

So I've been trying to get dynamic libraries to work in my XCode project under Mac OS X. So far no joy.

I am able to load the dylib file, but when I call dlsym to get the function pointer, it returns 0 and dlerror says symbol not found.

So I am wondering if there is a simple way to list the symbols that are exported from a dylib file. Any ideas would be great.

4 Answers 4

179

man 1 nm

https://web.archive.org/web/20160316222941/https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/nm.1.html

For example:

nm -gU /usr/local/Cellar/cairo/1.12.16/lib/cairo/libcairo-trace.0.dylib
3
  • 2
    Under OS X Leopard (10.5, yeah, I know...) you should use nm -gu , i.e. the -u option is lowercase. Apr 23, 2015 at 8:17
  • 4
    man 1 nm is self-contained and will continue working when command line changes :p
    – MK.
    Oct 16, 2015 at 12:33
  • 11
    @MK. man 1 nm lists a lot of things one can do with nm. Again, it's an external resource one can read through to discover a solution, but not a solution itself to the requested “a simple way to list the symbols that are exported from a dylib file”. “nm -gU ….dylib” is, however. Apr 27, 2016 at 4:32
66

Use otool:

otool -TV your.dylib

OR

nm -g your.dylib
2
  • 5
    On new macOS, otool -T will show otool: -T functionality obsolete use objdump -t Mar 3, 2017 at 13:36
  • While it's true that otool -T reports functionality obsolete in newer OS X, it's also true that (for dynamic libraries) objdump -t will report The file was not recognized as a valid object file.
    – TML
    Jul 25, 2017 at 19:33
16

Use nm -a your.dylib

It will print all the symbols including globals

0

Use Mach-OView for viewing all the Symbols in dylib

https://sourceforge.net/projects/machoview/

1
  • I was excited to have learned of this GUI but it crashed for me after I loaded a dylib. I'm using macOS Mojave. Jun 19, 2019 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.