c - Windows 是否有等同于 Unix GCC 的 __attribute__((weak)) 的 __declspec?

标签 c windows unix macros mingw

我想导入一些 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/

相关文章:

c++ - 通过本地 UNIX 套接字发送双倍

linux - Unix,替换错误错误?

c - 使用 C 语言使用系统调用查找具有特定扩展名的文件的数量

c - 在结构中将 const char 转换为 char 时出错?

c - 从 'uint8_t* {aka unsigned char*}' 到 'const char*' [-fpermissive] 的无效转换

c++ - 没有 DLL 的 JPEG 压缩

windows - 谁能帮我修复 Windows 10 上的 VBS 脚本,该脚本在电池电量不足时显示警告/MsgBox?

objective-c - 有没有办法显示 LLVM 在哪里自动矢量化?

windows - Perforce 安装在 Windows 的网络文件夹中

C++:如何将日期字符串转换为 int