clinuxlinkernm

Strange symbol name in output of nm command


I built a dynamic lib called InterfaceLayer.so. When I call:

> nm InterfaceLayer

As output, I get some symbols that look like:

00000e28  T _Z5startv

while I was expecting it to be "start", just as the name of the function I defined in the code.

Why does this happen?


Solution

  • That's because of C++ name mangling

    nm -C
    

    demangles them.

    To prevent name mangling,

    .

    my.h

      extern "C" 
      {
            void start();
            void finish();
      }
    

    This will give them "C" linkage, meaning they can't be overloaded, cannot pass by reference, nothing c++ :)