MinGW:使用__declspec(dllexport)或__attribute __((visibility("default"))))? [英] MinGW: Use __declspec(dllexport) or __attribute__((visibility("default")))?

查看:107
本文介绍了MinGW:使用__declspec(dllexport)或__attribute __((visibility("default"))))?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MinGW是否支持 __ declspec(dllexport)/ __ declspec(dllimport)?即使这样做,我还是应该使用 __ attribute __((visibility("default")))?基本上我应该根据平台或编译器来决定使用什么?

Does MinGW support __declspec(dllexport)/__declspec(dllimport)? Even if it does, should I rather use __attribute__((visibility("default")))? Basically should I decide what to use based on the platform or the compiler?

应该是这样吗?

#ifdef _MSC_VER
#   ifdef MYLIB_EXPORTS
#       define MYLIB_API __declspec(dllexport)
#   else
#       define MYLIB_API __declspec(dllimport)
#   endif
#else
#   define MYLIB_API __attribute__((visibility("default")))
#endif

还是这样?

#if defined(_WIN32) || defined(_WIN64)
#   ifdef MYLIB_EXPORTS
#       define MYLIB_API __declspec(dllexport)
#   else
#       define MYLIB_API __declspec(dllimport)
#   endif
#else
#   define MYLIB_API __attribute__((visibility("default")))
#endif

__ declspec(align(16))之类的东西呢? __ attribute __((aligned(16)))?

推荐答案

可见性.dllexport是平台事物,而不是编译器事物.因此,使用 __ declspec(dllexport)/ __ declspec(dllimport)(或 __ attribute __((dllexport))/ __ attribute __((dllimport)))与MinGW一起使用是可行的方法.看: http://gcc.gnu.org/wiki/Visibility#How_to_use_the_new_C.2B-.2B-_visibility_support

Visibility Vs. dllexport is a platform thing, not a compiler thing. So using __declspec(dllexport)/__declspec(dllimport) (or __attribute__((dllexport))/__attribute__((dllimport))) with MinGW is the way to go. See: http://gcc.gnu.org/wiki/Visibility#How_to_use_the_new_C.2B-.2B-_visibility_support

这篇关于MinGW:使用__declspec(dllexport)或__attribute __((visibility("default"))))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆