2010-01-29 48 views

回答

53
__attribute__((visibility("default"))) 

据我所知,没有相当于__declspec(dllimport)

#if defined(_MSC_VER) 
    // Microsoft 
    #define EXPORT __declspec(dllexport) 
    #define IMPORT __declspec(dllimport) 
#elif defined(__GNUC__) 
    // GCC 
    #define EXPORT __attribute__((visibility("default"))) 
    #define IMPORT 
#else 
    // do nothing and hope for the best? 
    #define EXPORT 
    #define IMPORT 
    #pragma warning Unknown dynamic link import/export semantics. 
#endif 
+6

没有预定义的_GCC宏,而是使用'__GNUC__'。 – 2016-06-11 23:44:17

+2

有关放置宏的位置的说明对未来的读者会很好。 – ManuelSchneid3r 2017-03-25 11:00:01