I find very frustrating to have to fix C++ errors happening at linkage time (especially undefined reference errors) due to the fact that all the function names are mangled. An example of mangled name:
_ZNK5boost7archive6detail11oserializerINS0_13text_oarchiveEN9galandria8UniverseEE16save_object_dataERNS1_14basic_oarchiveEPKv
It is so hard to read, and finding the actual function is even harder.
Is there a way to convince ld to output demangled names?
ld(The GNU Linker) is able to demangle C++ function names.lddocumentation on demangling from it'smanpage: (available here online)Let's see an example:
This is a simple valid code. This will compile but fail to link successfully because there is no implementation of
foo()andfoo(int)here. Now we'll compile it with the following command:It will compile successfully. Now let's try to link it with demangling disabled with the following command:
It should show linking errors with some weird mangled name like this:
See live on Coliru
Now let's try to link with demangling enabled with the following command:
We'll get errors with demangled function names with their arguments like this:
See live on Coliru
Here
-Wlmeans arguments to linker.As far as I know,
g++enables demangling automatically.