165

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.

bdesham's user avatar

bdesham

16.3k15 gold badges89 silver badges138 bronze badges

asked Dec 22, 2010 at 4:18

Gerald's user avatar

214

For example:

nm -gU /usr/local/Cellar/cairo/1.12.16/lib/cairo/libcairo-trace.0.dylib

From man 1 nm:

  -g     Display only global (external) symbols.
  -U     Don't display undefined symbols.

flogram_dev's user avatar

flogram_dev

43.1k11 gold badges109 silver badges162 bronze badges

answered Dec 22, 2010 at 4:23

MK.'s user avatar

4 Comments

Under OS X Leopard (10.5, yeah, I know...) you should use nm -gu , i.e. the -u option is lowercase.

man 1 nm is self-contained and will continue working when command line changes :p

@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.

How about for macOS frameworks:/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa

73

Use otool:

otool -TV your.dylib

OR

nm -g your.dylib

answered Oct 27, 2012 at 7:50

linuxbuild's user avatar

linuxbuild

16.3k6 gold badges65 silver badges87 bronze badges

2 Comments

On new macOS, otool -T will show otool: -T functionality obsolete use objdump -t

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.

17

Use nm -a your.dylib

It will print all the symbols including globals

answered Aug 29, 2013 at 7:00

Omkar Ramtekkar's user avatar

Comments

0

Use Mach-OView for viewing all the Symbols in dylib

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

answered Jun 3, 2016 at 11:14

Sahil Doshi's user avatar

2 Comments

I was excited to have learned of this GUI but it crashed for me after I loaded a dylib. I'm using macOS Mojave.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.