c++ ++静态链接 - 如何查看目标文件中的符号?

a文件 编译器链接器 (5)



如何查看.o文件中的符号? nm对我不起作用。 我用g ++ / linux。

只需运行: nm you_obj_file.o | c++filt nm you_obj_file.o | c++filt

您可以使用功能强大的objdump代替nm 。 有关详细信息,请参见手册页。 尝试objdump -t myfileobjdump -T myfile 。 使用-C标志,你也可以解析C ++名称,就像nm那样。

您可以使用nm -C .o/lib/exe ,例如:

 [email protected]:~/tmp/build$ nm -C libfile1.a file1.cpp.o: 0000000000000000 T f() 0000000000000000 W int fun<int>(int) 

使用nm -C如果只使用nm它将更具可读性

 [email protected]:~/tmp/build$ nm libfile1.a file1.cpp.o: 0000000000000000 T _Z1fv 0000000000000000 W _Z3funIiET_S0_ 



 [email protected]:~/tmp/build$ vi ../file1.cpp #include "head.h" void f() { int i = fun<int>(42); } 

Use the linker to help diagnose the error

Most modern linkers include a verbose option that prints out to varying degrees;

  • Link invocation (command line),
  • Data on what libraries are included in the link stage,
  • The location of the libraries,
  • Search paths used.

For gcc and clang; you would typically add -v -Wl,--verbose or -v -Wl,-v to the command line. More details can be found here;

For MSVC, /VERBOSE (in particular /VERBOSE:LIB ) is added to the link command line.

c++ linux g++ object-files