views:

415

answers:

5

Created basic C++ DLL and exported names using Module Definition file (MyDLL.def). After compilation I check the exported function names using dumpbin.exe I expect to see:

SomeFunction

but I see this instead:

SomeFunction = SomeFunction@@@23mangledstuff#@@@@

Why?

The exported function appears undecorated (especially compared to not using the Module Def file), but what's up with the other stuff?

If I use dumpbin.exe against a DLL from any commercial application, you get the clean: SomeFunction and nothing else......

UPDATE: I also tried removing the Module Definition and exporting the names using the "C" style of export, namely:

extern "C" void __declspec(dllexport) SomeFunction();

(Simply using "extern "C" did not create an exported function btw)

However, this still creates the same output, namely:

SomeFunction = SomeFunction@@@23mangledstuff#@@@@

UPDATE2: (Can't use Comment option on this website for some reason) I also tried the #define dllexport __declspec(dllexport) option and created a LIB with no problem. However, I don't want to have to provide a LIB file to people using the DLL in their C# application.

UPDATE3: RE: "Making sure I build the DLL correctly". Umm, that's why I'm asking the question. It's a plain vanilla C++ DLL (unmanaged code), compiled with C++ nothing but a simple header and code. Without Module Def I get mangled exported functions (I can create a static library and use the LIB no problem. I'm trying to avoid that). If I use extern "C" __declspec(dllexport) OR a Module Definition I get what appears to be an undecorated function name......the ony problem is that it is followed by an "=" and what looks like a decorated version of the function. I want to get rid of the stuff after the "=" - or at least understand why it is there.

As it stands, I'm pretty certain that I can call the function from C# using a P/Invoke.....I just want to avoid that junk at the end of the "=".

I'm open to suggestions on how to change the project/compiler settings, but I just used the standard Visual Studio DLL template - nothing special.

+4  A: 

You have to declare the functions as extern "C" if you don't want their names to be mangled.

jwismar
A: 

the SomeFunction@@@23mangledstuff#@@@@ is mangled to give the types and class of the C++ function. The simple exports are functions that are callable from C i.e. are written in C or else are declared extern "C' in C++ code. If is you want a simple interface you have to make the functions you export be use just C types and make them non member functions in the global namespace.

Mark
A: 

Basically, when you use functions in C++, parts of their names now include their signature and suchlike, in order to facilitate language features like overloading.

If you write a DLL using __declspec(dllexport), then it should also produce a lib. Link to that lib, and you will automatically be linked and the functions registered by the CRT at start-up time (if you remembered to change all your imports to exports). You don't need to know about name mangling if you use this system.

DeadMG
+1  A: 

Instead of using .def file just insert pragma comment like this

#pragma comment(linker, "/EXPORT:SomeFunction=_SomeFunction@@@23mangledstuff#@@@@")
wqw
+2  A: 

You can get what you want by turning off debug info generation. Project + Properties, Linker, Debugging, Generate Debug Info = No.

Naturally, you only want to do this for the Release build. Where the option is already set that way.

Hans Passant
THANK YOU! THANK YOU! THANK YOU!It's funny because I was just reading some other answers you wrote on here........You know, I spent way to much time researching this. I had people repeatedly telling me to use a Module Definition file, others would say "No" it has to be the "extern C"".....I even had people telling me to use 3 different options together. All this despite the fact that my module definition was ok. I just couldn't find someone to explain why there was extra "mangled" text shown by dumpbin.The remaining 10 hairs on my head solute you and live another day.
Bob
@Bob, great, sounds like an answer. Please don't hesitate to mark it that way. White check mark next to my post.
Hans Passant