Windows能否有__declspec等同于Unix GCC的__attribute __((弱))? [英] Does Windows have a __declspec equivalent to Unix GCC's __attribute__((weak))?
问题描述
我要进口一些C code,但覆盖其的main()
功能。我可以通过prefacing的C code的主要申报与 __属性__((弱))
,但是,这不会在Windows编译的Unix做到这一点,因为无论是草莓Perl的海湾合作委员会MinGW的也的GCC识别 __ __属性((弱))
。
I want to import some C code but override its main()
function. I can do this in Unix by prefacing the C code's main declaration with __attribute__((weak))
, however, this won't compile in Windows, because neither Strawberry Perl's GCC nor MinGW's GCC recognize __attribute__((weak))
.
阅读文档在线, __ declspec
看起来功能相似。是否有一个 __ declspec
等同于Unix GCC的 __属性__((弱))
宏?
Reading the docs online, __declspec
seems to function similarly. Is there a __declspec
equivalent to Unix GCC's __attribute__((weak))
macro?
这是一个更具体的版本<一个href=\"http://stackoverflow.com/questions/12395130/trouble-using-scriptedmain-in-mingw/12395171\">earlier问题我张贴。
This is a more specific version of an earlier question I posted.
推荐答案
有与MSVC另一种方式,我的认为的会,如果你愿意使用它。
There's another way with MSVC that I think would work if you care to use it.
/*
* pWeakValue MUST be an extern const variable, which will be aliased to
* pDefaultWeakValue if no real user definition is present, thanks to the
* alternatename directive.
*/
extern const char * pWeakValue;
extern const char * pDefaultWeakValue = NULL;
#pragma comment(linker, "/alternatename:_pWeakValue=_pDefaultWeakValue")
请参阅这个老这么回答了解一些其他的选择。
See this old SO answer for some other options.
这篇关于Windows能否有__declspec等同于Unix GCC的__attribute __((弱))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!