全局变量dll导出/导入

时间:2017-09-10 14:21:53

标签: c++ dll

我有如下通常的宏:

#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未在上面引用的头文件中定义。

0 个答案:

没有答案