linuxstatic-librariessymbolsstatic-linkingnm

NM linux command output meaning


I'am searching a specific symbol in my lib:

nm --undefined-only -A libcpprest.a | grep "error_category"

and I obtain:

libcpprest.a:json.cpp.o:          U _ZNSt14error_categoryC2Ev
libcpprest.a:json.cpp.o:          U _ZNSt14error_categoryD2Ev
libcpprest.a:json.cpp.o:          U _ZTISt14error_category

what's meaning "_ZNSt14" and "C2Ev"?

Is there a way to clean nm output?


Solution

  • C++ compilers perform name mangling to support features like function overloading (using the same function name multiple times with different signatures, accepting different arguments). Different compilers may use different conventions for their name mangling.

    You can use the c++filt utility to demangle the names into a more readable form. In your case:

    > c++filt -n _ZNSt14error_categoryC2Ev
    std::error_category::error_category()
    
    > c++filt -n _ZNSt14error_categoryD2Ev
    std::error_category::~error_category()
    
    > c++filt -n _ZTISt14error_category
    typeinfo for std::error_category
    

    This is 3 different symbols containing the name "error_category": a constructor, a destructor and type information.