0

I got usual macros as below:

#ifdef PLATFORM_WINDOWS
    #ifdef BUILD_SHARED
        #define API __declspec(dllexport)
    #else
        #define API __declspec(dllimport)
    #endif
#else
    #define API
#endif  

(The lib compiles with /DBUILD_SHARED)

Then I have a global union object which I want to export/import:
header file:

#ifdef __cplusplus  
extern "C" {  
#endif  
//definition of union type   
API extern union U global;  
#ifdef __cplusplus  
} 
#endif 

source file:

// include header
API union U global;

The lib compiles fine, but while linking an executable to it I get linker error unresolved external symbol _global. I'm using MSVC (VS 2015). Not sure if C linkage has anything to do with it. I'm not even sure if it actually uses C linkage because Intellisense shows as __cplusplus is not defined in header file quoted above.

Criss
  • 581
  • 5
  • 17
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – user0042 Sep 10 '17 at 14:23
  • Take care about the name mangling. – user0042 Sep 10 '17 at 14:23
  • @user0042 I know what linker errors are, but I have no idea where this one came from. How do I care about name mangling? – Criss Sep 10 '17 at 14:33
  • _"How do I care about name mangling?"_ Compile C code with the C-compiler and C++ code with `extern` with the C++-compiler. – user0042 Sep 10 '17 at 14:34

0 Answers0