Jimm
Jimm

Reputation: 8505

printing the c++ name mangling

I am reading a c++ book which states that linker is usually passed mangled names as opposed to original names. So, i am trying to see what mangled names would look like. Hence, i created a class called Test, which just includes function signatures and saved it to a file called name_mangling.cpp

Then in the main method, i call those functions. I first compiled the file to .o and then tried linking it with command such as

g++ -o name_mangling name_mangling.o

I was hoping to see mangled names, but g++ printed actual names such as

undefined reference to `Test::Test(char const*)'

but on the other hand, i have seen, mangled names, when i try to link to a shared object such as .so. Why does g++ prints the mangled names in case of .so and not the above case?

Upvotes: 1

Views: 1433

Answers (1)

Mario
Mario

Reputation: 36487

It won't show the mangled names, because it know the actual/real names written in code. Showing the mangled name would be counterproductive considering you might just have some name misspelled (and the mangled names are harder to work with).

As mentioned, under Linux/GCC there's the "nm" tool to print the mangled names. Under Windows, you can try Dependency Walker, which used to be part of the samples for Visual C++ and is also very useful to ensure you've got all dynamic link libraries required on startup.

Upvotes: 3

Related Questions