我有如下通常的宏:
#ifdef PLATFORM_WINDOWS
#ifdef BUILD_SHARED
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport)
#endif
#else
#define API
#endif
(lib使用/DBUILD_SHARED
编译)
然后我有一个全局联合对象,我想导出/导入:
头文件:
#ifdef __cplusplus
extern "C" {
#endif
//definition of union type
API extern union U global;
#ifdef __cplusplus
}
#endif
源文件:
// include header
API union U global;
lib编译正常,但在将可执行文件链接到它时,我得到链接器错误unresolved external symbol _global
。我正在使用MSVC(VS 2015)。不确定C链接是否与它有关。我甚至不确定它是否实际使用C链接,因为Intellisense显示为__cplusplus
未在上面引用的头文件中定义。