Is there anything to change the exports name mangling scheme in GCC?
I'm trying to build a project I have and it has several exported functions. The functions follow the stdcall convention and they get mangled if compiled with GCC as
Func@X
Other compilers mangle the name like this:
_Func@X
Is any way I can force GCC to mang开发者_开发问答le the names of the exported functions to the later example?
See this answer.
int Func() __asm__("_Func@X");
This will force GCC to name the symbol _Func@X
regardless of what it would have done normally.
Oh right, @
is special: it's used for symbol versioning. I thought that __asm__("...@...")
used to work, but I guess it doesn't anymore.
int Func() __asm__("_Func");
__asm__(".symver _Func, _Func@X");
This must be accompanied by a version script file, like:
1 {
global:
_Func;
};
given to gcc -Wl,--version-script=foo.version
when linking.
See the GCC manual regarding -fleading-underscore. Do read the warnings about the consequences of this action however; it may not be the solution you think it is.
The best bet when dealing with function name mangling on Windows is to always use a .def
file. This will work the same regardless of the compiler. Typically you only need the EXPORTS
section:
EXPORTS
Func1
Func2
...
精彩评论