문제

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?

Should it be like this?

#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

Or like this?

#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

And what about things like __declspec(align(16)) Vs. __attribute__((aligned(16)))?

도움이 되었습니까?

해결책

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

다른 팁

Yes MinGW supports __declspec dllimport/dllexport (http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html). You should use it, if it makes easier to support multiple compilers. In general compiler specific attributes are not portable, and you should use macro wrappers (as in your example).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top