From LQWiki
Jump to: navigation, search

nm is a tool for listing symbols within a program or library or object file stored in either ELF or a.out format. When a programmer creates a program, functions tend to have names, which are kept even after the program has been compiled.

nm will list these names, most usefully when you are looking at a library (usually the symbols have been stripped from programs anyway).

For example you might be trying to compile something with GTK. You're sure you're using the right flags for GCC to get it to link up with the library, but you're getting undefined symbol errors anyway. What's wrong?

You can run a command something like:

 nm /usr/lib/libgtk-x11-2.0.a | grep somefunc

and check to see whether the function's actually there.

You'll see output like:

00002884 T IDL_interface_new
00000004 C __IDL_is_okay
00000004 C __IDL_is_parsing
         U __IDL_lex_cleanup
         U __IDL_lex_init
00001601 T IDL_list_concat
00004e4c T IDL_list_length

The rightmost column represents the symbol.

The second column gives the symbol's type. "T" means that the function is defined in the object file; "T" stands for text, the code section of the object. "U" means that the function is not defined in the object file. The undefined symbol will have to be provided for from somewhere else, at link time, if it's going to be used. "C" means common. See its man page for full reference.

The leftmost column represents the "symbol's value".