在Linux中显式导出共享库函数

the*_*tor 45 c++ linux

是否有Linux等效的__declspec(dllexport)表示法从共享库中显式导出函数?由于某些原因我使用的工具链,非类成员的函数不会出现在生成的共享库文件中.

Tra*_*kel 78

__attribute__((visibility("default")))
Run Code Online (Sandbox Code Playgroud)

并没有相当于__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
Run Code Online (Sandbox Code Playgroud)

  • 关于放置宏的位置的注释对未来的读者来说会很好. (5认同)

Chr*_*s H 29

http://gcc.gnu.org/wiki/Visibility

这是一个关于msvc和gcc导出的完整教程.

  • 考虑总结关键/相关点,因为仅链接答案不是很好,特别是当外部URL消失时. (6认同)