I am trying to build a dll written in C and which will be imported by other programs also written in C.
So all the function that the dll is exporting are defined in a .dll "without __declspec(dllexport)" (intentional). I have defined a .def file with just an Export section and name of the functions I want to export (unmangled names).
I am using vc71/vs2003 to build this and I am still getting mangled names (which I can see if I open the .lib in notepad). Also just for clarification, visual studio causes name mangling in C code as well (most resources I could find mentioned it being an issue with only C++).
How can I prevent this name mangling?
Further Information:
The mangled names are of the form 'functionName@integer' where integer represent the parameter size in bytes (and not ordinal). For example,
From .lib: _PrepareSeverResponse@8
Function declaration in .h: char* PrepareSeverResponse(unsigned int* size ,handshake* ws_handshake);
.def: EXPORTS PrepareSeverResponse
Calling Convention: __stdcall(/Gz)
Hope this makes it clearer.
Changing calling convention to cdecl worked for me. The extern "C" solution won't of much help to me as in my case the problem was with name mangling while compiling .C files where as if I understand it correctly the extern "C" solution is for suppressing name mangling when compiling cpp files.
In order to prevent name mangling, you need to wrap your headers with extern C
:
#ifdef __cplusplus
extern "C" {
#endif
// Headers
#ifdef __cplusplus
}
#endif
This will force the symbols to their C-style (unmangled) names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With