I have written a short essay about the problems of MinGW GCC generating DLL for dynamic link libraries. The writing was not comprehensive at the time. Recently, I have encountered writing new questions. Here's a note to make a supplement.
Normally, if a function in a DLL takes _stdcall, the function name in the generated DLL is decorated.
For example, there are the following functions:
Dll.c
int _stdcall Add (int a, int b)
{
return a + B;
}
The function name in the final DLL file is [email protected]
But sometimes we want the function name not to add this adornment, just like the Windows API function. If we use the VS compiler, we need to write a def file. If you export a lot of functions, this is cumbersome.
The use of MinGW gcc is much simpler. The following statements can be implemented:
GCC dll.c-shared-o dll2.dll-wl,--kill-at,--output-def,dll2.def,--out-implib,dll2.a
The function name in this generated dll2.dll does not have an extra decoration.
How this DLL is used. When we compile with GCC we need to pass a parameter to the linker:
GCC-WL,--enable-stdcall-fixup main.c dll2.a-o test.exe
MinGW GCC generating DLL for dynamic link Libraries Summary (supplemental)