📅 2014-Aug-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ nm, object file, symbols ⬩ 📚 Archive
nm
is a very useful command for programmers. It can be used to list the symbols defined in an executable, object file (.o
) or shared object library file (.so
).
I typically need this command when the compiler throws me a undefined reference error. By searching for the reference symbol among the symbols exported by a library file, I can figure out if that is the one that needs to be linked into the target executable.
-g
option:$ nm -g foo.so
Other options that I find useful:
-C
: This option demangles symbol names to the names used in C or C++ code. By default, symbol names are mangled. The C symbols have extra underscores and the C++ symbols are completely mangled to encode the namespace, class and type information.
-A
: Prepend each line with path of object file. This is useful when you pipe this output through other programs, like grep.
-D
: Display dynamic symbols, rather than normal symbols. By default, the symbols in the .symtab
and .strtab
sections are shown. By specifying this option, the symbols in .dynsym
and .dynstr
sections are shown.
--defined-only
: Use this option to get only the symbols defined in the object file. By default, all the symbols in the object file are shown. I typically use this when I am solving an undefined reference problem.
Tried with: binutils 2.24 and Ubuntu 14.04