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

时间:2021-08-17 23:30:13

Is there a Linux equivalent of __declspec(dllexport) notation for explicitly exporting a function from a shared library? For some reason with the toolchain I'm using, functions that aren't class members don't appear in the resulting shared library file.

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

2 个解决方案

#1


56  

__attribute__((visibility("default")))

And there is no equivalent of __declspec(dllimport) to my knowledge.

据我所知,没有相当于__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

#2


26  

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

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

This is a complete tutorial on exporting in both msvc and gcc.

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

#1


56  

__attribute__((visibility("default")))

And there is no equivalent of __declspec(dllimport) to my knowledge.

据我所知,没有相当于__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

#2


26  

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

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

This is a complete tutorial on exporting in both msvc and gcc.

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