How to view symbols in object files?

C++LinuxG++Object Files

C++ Problem Overview


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

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

Have you been using a cross-compiler for another platform? If so, you need to use the respective nm or objdump commmand.

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.

Solution 3 - C++

There is a command to take a look at which functions are included in an object file or library or executable:

nm

Solution 4 - C++

Just run: nm you_obj_file.o | c++filt

Solution 5 - C++

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>(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<int>(42);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnakiyaView Question on Stackoverflow
Solution 1 - C++DarkDustView Answer on Stackoverflow
Solution 2 - C++SchedlerView Answer on Stackoverflow
Solution 3 - C++Alok SaveView Answer on Stackoverflow
Solution 4 - C++uol3cView Answer on Stackoverflow
Solution 5 - C++JayhelloView Answer on Stackoverflow