26
是否存在用于从共享库中显式导出函数的Linux等效项__declspec(dllexport)
?出于某种原因,我正在使用工具链,不是类成员的函数不会出现在生成的共享库文件中。在Linux中显式导出共享库函数
是否存在用于从共享库中显式导出函数的Linux等效项__declspec(dllexport)
?出于某种原因,我正在使用工具链,不是类成员的函数不会出现在生成的共享库文件中。在Linux中显式导出共享库函数
__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
http://gcc.gnu.org/wiki/Visibility
这是两个MSVC和gcc导出一个完整的教程。
没有预定义的_GCC宏,而是使用'__GNUC__'。 – 2016-06-11 23:44:17
有关放置宏的位置的说明对未来的读者会很好。 – ManuelSchneid3r 2017-03-25 11:00:01