C++ : Finding out decorated names

Vhaerun picture Vhaerun · Oct 10, 2008 · Viewed 8.3k times · Source

How can I find out the decorated name that will be asigned to each method name ? I'm trying to find out what the decorated name is , so that I may export it , in a DLL .

Answer

paercebal picture paercebal · Oct 10, 2008

.DEF file are still being used?

Forget .DEF files. They are a thing of the past.

Export your functions, be them C functions or C++ symbols, through __declspec(dllimport/dllexport).

If you really need undecorated names, use as suggested by Greg Hewgill, the __declspec(dllimport/dllexport) keywords, combined with extern "C", which will strip those symbols of their decoration...

Are you sure you want to remove the C++ decoration?

There are some valid reasons for that: You want to export code that will be used by C code, or you want to use your DLL from modules compiled with different compilers.

And for the second reason, I would instead produce one DLL per compiler, and keep the decorations.

Aside those reasons, why do you want the decorations removed?

C++ decorations/name mangling is not Evil

Quite the contrary.

If you are working with one compiler (and I suppose you do, because your want to use the decorated names, not extern "C" ones), then keep the C++ decoration/name mangling.

In this way, you'll be able to use full C++ power, that is, namespaces, classes, function/method overloads, etc..

Still, playing manually with symbol decorations is a recipe for disaster: Use dllexport to export your symbols without having to deal with yet another (.DEF) file.