Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC compiling a dll with __stdcall

When we compile a dll using __stdcall inside visual studio 2008 the compiled function names inside the dll are.

FunctionName

Though when we compile the same dll using GCC using wx-dev-cpp GCC appends the number of paramers the function has, so the name of the function using Dependency walker looks like.

FunctionName@numberOfParameters or == FunctionName@8

How do you tell GCC compiler to remove @nn from exported symbols in the dll?

like image 474
Chad Avatar asked Sep 20 '08 07:09

Chad


3 Answers

__stdcall decorates the function name by adding an underscore to the start, and the number of bytes of parameters to the end (separated by @).

So, a function:

void __stdcall Foo(int a, int b);

...would become _Foo@8.

If you list the function name (undecorated) in the EXPORTS section of your .DEF file, it is exported undecorated.

Perhaps this is the difference?

like image 81
Roger Lipscombe Avatar answered Nov 07 '22 23:11

Roger Lipscombe


Just use -Wl,--kill-at on the gcc command line, which will pass --kill-at to the linker.

References:

  • http://sourceware.org/binutils/docs/ld/Options.html#Options
  • http://www.geocities.com/yongweiwu/stdcall.htm
like image 23
CesarB Avatar answered Nov 07 '22 21:11

CesarB


You can also use -Wl,--add-stdcall-alias to your linker options in GCC. This will ensure that both function names (decorated and undecorated) are present and can be used as alias.

like image 2
Matthias Avatar answered Nov 07 '22 21:11

Matthias