How to view symbols in object files?

前端 未结 5 1167
旧时难觅i
旧时难觅i 2021-01-30 03:55

How can I view symbols in a .o file? nm does not work for me. I use g++/linux.

5条回答
  •  温柔的废话
    2021-01-30 04:14

    You can use nm -C .o/lib/exe, for example:

    xiongyu@ubuntu:~/tmp/build$ nm -C libfile1.a 
    
    file1.cpp.o:
    0000000000000000 T f()
    0000000000000000 W int fun(int)
    

    using nm -C it will be more readable, if you just use nm:

    xiongyu@ubuntu:~/tmp/build$ nm libfile1.a 
    
    file1.cpp.o:
    0000000000000000 T _Z1fv
    0000000000000000 W _Z3funIiET_S0_
    

    as we see it's not so readable.

    Below is what my file1.cpp like:

    xiongyu@ubuntu:~/tmp/build$ vi ../file1.cpp 
    #include "head.h"
    void f()  {
         int i = fun(42);
    }
    

提交回复
热议问题