nm: Usage, Options & Common CI Errors
nm prints the symbol table of an object, archive, or shared library.
nm is the diagnostic you reach for when a link fails. It tells you whether a symbol is Defined (T/D), Undefined (U), or hidden, which turns a vague "undefined reference" into a concrete "this object never defined it".
What it does
nm lists symbols from object files, static archives, and shared libraries, with a type letter per symbol: T (text/code), D (data), B (bss), U (undefined), W (weak), and lowercase for local symbols. It is the first tool to reach for when diagnosing link errors.
Common usage
nm app.o # list all symbols
nm -C app.o # demangle C++ names
nm -D libfoo.so # dynamic symbols of a .so
nm -u app.o # only undefined symbols
nm libfoo.a | grep ' T myFunc' # who defines myFunc?Options
| Flag | What it does |
|---|---|
| -C / --demangle | Demangle C++ symbol names |
| -D / --dynamic | Show dynamic symbols (for .so) |
| -u | Show only undefined symbols |
| -g | Show only external (global) symbols |
| --defined-only | Show only defined symbols |
Common errors in CI
"nm: file: no symbols" means the object was stripped or compiled without a symbol table. To debug an "undefined reference", run nm -C on your objects to confirm which has the symbol as U (needs it) and which library has it as T (defines it) - if no archive defines it, you are missing a -l. For shared libraries use nm -D; plain nm shows little on a stripped .so. C++ names are mangled - always add -C.