我有一个C++共享库。该库有要导出的文件。我使用的是Qt,这很容易,但我不能再使用它了。所以我需要一个涵盖Linux和Windows的纯C++版本。所以我想出了以下宏定义。C++共享库宏
纯C++
#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
// Microsoft
#define MY_SHARED_EXPORT __declspec(dllexport)
#elif defined(__linux__) || defined(UNIX) || defined(__unix__) || defined(LINUX)
// GCC
#define MY_SHARED_EXPORT __attribute__((visibility("default")))
#else
// do nothing and hope for the best?
#define MY_SHARED_EXPORT
#pragma WARNING: Unknown dynamic link import/export semantics.
#endif
Qt的C++
#if defined(MY_LIBRARY)
# define MY_SHARED_EXPORT Q_DECL_EXPORT
#else
# define MY_SHARED_EXPORT Q_DECL_IMPORT
#endif
目前我使用Qt的C++变体。 我的问题是,如果用纯C++变体替换Qt变体是安全的,如上所示。他们是否等同?
任何帮助表示赞赏,在此先感谢。
我建议您查看Q_DECLARE_ *宏的定义 –