How to print a list of symbols exported from a dynamic library

MacosDylib

Macos Problem Overview


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.

Macos Solutions


Solution 1 - Macos

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

Solution 2 - Macos

Use otool:

otool -TV your.dylib

OR

nm -g your.dylib

Solution 3 - Macos

Use nm -a your.dylib

It will print all the symbols including globals

Solution 4 - Macos

Use Mach-OView for viewing all the Symbols in dylib

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGeraldView Question on Stackoverflow
Solution 1 - MacosMK.View Answer on Stackoverflow
Solution 2 - MacoslinuxbuildView Answer on Stackoverflow
Solution 3 - MacosOmkar RamtekkarView Answer on Stackoverflow
Solution 4 - MacosSahil DoshiView Answer on Stackoverflow