Pregunta

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)))?

¿Fue útil?

Solución

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

Otros consejos

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).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top