MinGW g ++. Exe when compiled DLL, export issues of the function name with @

Today, trying to write a simple Dll with CodeBlocks, found the back of the generated dll file export function name has a @xxx

Seen from libDll2.def generated:

EXPORTS
    DllMain@12 @1
    Max@8 @2
    SomeFunction@4 @3
    funReturnStr2@4 @4
    funReturnStr@0 @5
    updateInt2@4 @6
    updateInt@4 @7
    updateStr@4 @8

As for the function name will bring back @ explain why export:

_stdcall function calling convention will be @, behind the numbers indicate parameters Total Number of Bytes, because _stdcall function needs to be emptied caller stack, it is necessary to know the parameters of the share size. 

_cedcl function calling convention without @ and digital back, because _cedcl function calling convention empty stack by the caller. 

Source: https://bbs.csdn.net/topics/380193271

 

At this time, when loading this dll in another application, call the Max function, you need to use: GetProcAddress (the HDLL, " Max @ 8 ");

Such an approach, people feel very cool.

Then use the MinGW g ++. Exe how to make the function name of the compiled dll do with it!?

At first, I found this description:  https://www.cnblogs.com/lichmama/p/4126323.html  (MinGW (GCC) compiler DLL files)

Which refers to:

Gcc can be found at the link stage by specifying --kill- to eliminate this situation at parameters. 

d: \ the Test > 
# compile command 
d: \ the Test > mingw32-gcc -c - DBUILD_DLL mydll.c 
# execute link command to generate mydll.dll and static library files libmydll.a 
d: \ the Test > mingw32-gcc -shared mydll.dll mydll.o -Wl -o, - the kill-AT, - OUT - IMPLIB, libmydll.a 
Creating Library File: libmydll.a

 

When prompted, I set in the CodeBlocks:

Then compile time, suggesting: 

mingw32-g++.exe -O2 -Wall -DBUILD_DLL -c D:\soft\c\Dll2\main.cpp -o obj\Release\main.o
mingw32-g++.exe -shared -Wl,--output-def=bin\Release\libDll2_test.def -Wl,--out-implib=bin\Release\libDll2_test.a -Wl,--dll obj\Release\main.o -o bin\Release\Dll2.dll -s --kill-at -luser32
mingw32-g++.exe: error: unrecognized command line option '--kill-at'

---> Unrecognized command-line option '--kill-at'

what's the situation?

I see that in this article using: mingw32-gcc, and I am now used is mingw32-g ++ exe, is it caused by different compilers.?

I gcc command line parameters should not have to understand, I will continue to search the Internet ...

Then find this one: https://www.linuxidc.com/Linux/2015-12/126123.htm  (problems and create a DLL using MinGW should be noted)

Among them, I see such a sentence:

MinGW how to create a standard DLL. MinGW create a standard DLL, you should use __declspec (dllexport), including the extern  " C " are all the same and VC. 
Note, however, so the compiler generated DLL linking, the exported function names are the tail with @nn, in order to get rid of them, must be used in the linker parameter settings -Wl, - the kill-AT , which tells the linker to create a DLL when you export a function name without trailing with @nn.
Note, the above also specifies the parameters set by the parameters in the link in the NetBeans CDT.

Then I re-set a bit CodeBlocks:

Compile again, successfully.

So now, I wrote a little -Wl , then I Baidu a bit -Wl, see the explanation: https://blog.csdn.net/wang_hufeng/article/details/53899120  (gcc compiler option -Wl)

-Wl option tells the compiler to pass parameters back to the linker.

编译 dll 成功后,再次打开 libDll2.def 查看函数定义:

EXPORTS
    DllMain = DllMain@12 @1
    Max = Max@8 @2
    SomeFunction = SomeFunction@4 @3
    funReturnStr = funReturnStr@0 @4
    funReturnStr2 = funReturnStr2@4 @5
    updateInt = updateInt@4 @6
    updateInt2 = updateInt2@4 @7
    updateStr = updateStr@4 @8

这个时候,在另一个应用程序中,加载 Dll2.dll 后,调用 Dll2 中的函数 Max 的正确写法就变成理想中的: 

GetProcAddress(hDll, "Max");

 

 

扩展资料:https://www.cnblogs.com/jiftle/p/8451336.html (DLL编写中extern “C”和__stdcall的作用)

 

完。

 

Guess you like

Origin www.cnblogs.com/personnel/p/11275690.html