Linux 如何查看目标文件中的符号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3880924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to view symbols in object files?
提问by nakiya
How can I view symbols in a .o file? nm does not work for me. I use g++/linux.
如何查看 .o 文件中的符号?nm 对我不起作用。我使用 g++/linux。
采纳答案by DarkDust
Instead of nm
, you can use the powerful objdump
. See the man page for details. Try objdump -t myfile
or objdump -T myfile
. With the -C
flag you can also demangle C++ names, like nm
does.
取而代之的是nm
,您可以使用强大的objdump
. 有关详细信息,请参阅手册页。尝试objdump -t myfile
或objdump -T myfile
。使用该-C
标志,您还可以像这样nm
对C++ 名称进行解密。
回答by Alok Save
There is a command to take a look at which functions are included in an object file or library or executable:
有一个命令可以查看目标文件或库或可执行文件中包含哪些函数:
nm
回答by Schedler
Have you been using a cross-compiler for another platform? If so, you need to use the respective nm
or objdump
commmand.
您是否一直在为另一个平台使用交叉编译器?如果是这样,您需要使用相应的nm
或命令objdump
。
For example, if you have used XXX-YYY-gcc
to compile the .o file, you need to use XXX-YYY-nm
or XXX-YYY-objdump
to process the files.
例如,如果您曾经XXX-YYY-gcc
编译过 .o 文件,则需要使用XXX-YYY-nm
或XXX-YYY-objdump
处理这些文件。
回答by Jee lee
Just run: nm you_obj_file.o | c++filt
赶紧跑: nm you_obj_file.o | c++filt
回答by Jayhello
You can use nm -C .o/lib/exe
, for example:
您可以使用nm -C .o/lib/exe
,例如:
xiongyu@ubuntu:~/tmp/build$ nm -C libfile1.a
file1.cpp.o:
0000000000000000 T f()
0000000000000000 W int fun<int>(int)
using nm -C
it will be more readable, if you just use nm
:
使用nm -C
它将更具可读性,如果您只是使用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:
下面是我file1.cpp
喜欢的:
xiongyu@ubuntu:~/tmp/build$ vi ../file1.cpp
#include "head.h"
void f() {
int i = fun<int>(42);
}