September 10, 2018 · Don't Forget linux

Listing the available functions/symbols in a static library

Recently, I've been building grpc and flatbuffers, and kept getting undefined reference errors. GNU nm to the rescue.

To list symbols in static libraries:

nm -g -C <path_to_lib.a>

Where -g lists symbols that are external, and -C demangles the name. Most importantly, if the symbol value is Undefined, then it isn't just a missing link. ;)

Alternatively, one can also try:

readelf -sW <path_to_lib.a>  | awk '$4 == "FUNC"' | c++filt