Arcanelab Blog
text

otool / nm examples Printing object files included in the library and their exported…

otool / nm examples

Printing object files included in the library and their exported functions

$>otool -SV /usr/local/lib/libSDL2_image.a

Archive : /usr/local/lib/libSDL2_image.a
Table of contents from: /usr/local/lib/libSDL2_image.a(__.SYMDEF SORTED)
size of ranlib structures: 392 (number 49)
size of strings: 696
object           symbol name
IMG.o            _IMG_Init
IMG_jpg.o        _IMG_InitJPG
IMG_png.o        _IMG_InitPNG
IMG_tif.o        _IMG_InitTIF
IMG_webp.o       _IMG_InitWEBP
IMG.o            _IMG_Linked_Version
IMG.o            _IMG_Load
IMG_bmp.o        _IMG_LoadBMP_RW
IMG_bmp.o        _IMG_LoadCUR_RW
...

Printing shared libraries used

$> otool -L /usr/local/lib/libSDL2.dylib

/usr/local/lib/libSDL2.dylib:
    /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib (compatibility version 5.0.0, current version 5.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /System/Library/Frameworks/ForceFeedback.framework/Versions/A/ForceFeedback (compatibility version 1.0.0, current version 1.0.2)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
...

Printing invoked external functions from executable

$> otool -IV testapp

testapp:
Indirect symbols for (__TEXT,__stubs) 38 entries
address            index name
0x000000010001bc0e   134 ___tolower
0x000000010001bc14   135 _fclose
0x000000010001bc1a   136 _fopen
0x000000010001bc20   137 _fread
0x000000010001bc26   138 _fseek
0x000000010001bc2c   139 _ftell
0x000000010001bc32   140 _memcpy
0x000000010001bc38   141 _memset
0x000000010001bc3e   142 _printf
0x000000010001bc44   143 _puts
0x000000010001bc4a   144 _snprintf
0x000000010001bc50   145 _strlen
...

Listing all symbols (internal/external) in binary files

nm [file]

Example snippet:
0000000100001560 T _main
                 U _memcpy
                 U _memset
                 U _printf
                 U _puts
                 U _snprintf
                 U _strlen
                 U dyld_stub_binder

More info on nm on Wikipedia.