我想导入一些 C 代码但覆盖它的 main()
函数。我可以在 Unix 中通过在 C 代码的主声明前加上 __attribute__((weak))
来做到这一点,但是,这不会在 Windows 中编译,因为 Strawberry Perl 的 GCC 和 MinGW 的 GCC 都无法识别 __attribute__((弱))
。
在线阅读文档,__declspec
似乎功能相似。是否有一个 __declspec
等同于 Unix GCC 的 __attribute__((weak))
宏?
这是一个更具体的版本 earlier我发布的问题。
最佳答案
我认为还有另一种使用 MSVC 的方法,如果您愿意使用它的话。
/* * 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")
参见 this old SO answer对于其他一些选项。
关于c - Windows 是否有等同于 Unix GCC 的 __attribute__((weak)) 的 __declspec?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12396333/