Unable to prevent name change

I am trying to create a dll written in C and which will be imported by other programs also written in C.

Thus, the entire function that the dll exports is defined in the .dll "without __declspec (dllexport)" (intentionally). I defined a .def file that has only the Export section and the name of the functions I want to export (unmangled names).

I use vc71 / vs2003 to create it and I still get malformed names (which I can see if I open .lib in notepad). In addition, for clarification, visual studio also causes name manipulation in C code (most of the resources that I could find mentioned that this was only a problem with C ++).

How can I prevent this name from appearing?

Additional Information:

The changed names are of the form 'functionName @integer', where integer represents the size of the parameter in bytes (not the serial number). For instance,

From .lib: _PrepareSeverResponse @ 8

Function declaration in .h: char * PrepareSeverResponse (unsigned int * size, handshake * ws_handshake);

.def: EXPORT PrepareSeverResponse

Calling Convention: __stdcall (/ Gz)

We hope this becomes clearer.

+4
source share
4 answers

Changing the calling convention in cdecl worked for me. The extern "C" solution will not help me much, since in my case the problem was that when compiling .C files, as if I understood correctly, the external "C" solution is designed to suppress name manipulation when compiling cpp files.

+5
source

To prevent name manipulation, you need to wrap extern C headers:

 #ifdef __cplusplus extern "C" { #endif // Headers #ifdef __cplusplus } #endif 

This will cause characters to appear in C-style (unmangled) names.

+2
source

The name you see is not related to C ++; this Microsoft calling convention is the name of the decoration , and also refers to code C. You can return the alias of these names to your .DEF file:

 EXPORTS PrepareServerResponse=_PrepareSeverResponse@8 _PrepareSeverResponse@8 

Please note that when linking the library to another program, the host program will look for a framed name. The main case when you might need an undecorated name is that you expect users to load your DLL using LoadLibrary and GetProcAddress .

+2
source

Without seeing what you characterize as "name manipulation," I would suggest that you need to install Visual Studio on Compile as C Code (/TC) .

In Properties->C/C++->Advanced->Compile As . You can select this option for the entire project, as this is your intention.

0
source

Source: https://habr.com/ru/post/1379430/


All Articles