gcc 如何使用Linux的`_declspec(dllexport)`编译代码

fae0ux8s  于 3个月前  发布在  Linux
关注(0)|答案(1)|浏览(85)

关于__declspec(dllexport)有一些问题,但似乎没有一个适合我的用例:
1.源代码最初是为Windows编写的,使用__declspec(dllexport)
1.希望在不修改源代码 * 的情况下为Linux目标 * 重新编译。
我尝试使用GCC 11.4,其中提到:
您可以使用__declspec(dllexport)作为__attribute__ ((dllexport))的同义词,以便与其他编译器兼容。
但是,我似乎不能让它工作。

error: expected constructor, destructor, or type conversion before ‘(’ token
    8 | #define dll_export __declspec(dllexport)

error: ‘dllexport’ was not declared in this scope
   23 | void __declspec(dllexport) _Err_msg(int err, char*& msg);

字符串
希望有一些神奇的GCC标志,我错过了,或另一种非侵入性的垫片,我可以使用它来编译为Linux。任何帮助感谢!

pw9qyyiw

pw9qyyiw1#

-D选项怎么样?
-D名称=定义
definition的内容被标记化和处理,就像它们出现在'#define'指令中的翻译阶段3中一样。特别是,定义被嵌入的换行符截断。

gcc -D__declspec(dllexport)=__attribute__((dllexport)) ...

字符串
类似于其他Windows特定的东西

相关问题