Linux中显式导出共享库函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2164827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:44:58  来源:igfitidea点击:

Explicitly exporting shared library functions in Linux

c++linux

提问by theactiveactor

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)符号用于从共享库中显式导出函数?由于我使用的工具链的某种原因,不是类成员的函数不会出现在生成的共享库文件中。

采纳答案by Travis Gockel

__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

回答by Chris H

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 中导出的完整教程。