However, the compiler keeps giving me “duplicate symbol” error on WPSent:
wasm-ld : error : duplicate symbol: WPSent
and is fine with the enum. I also tried
#pragma once
but that produces the same error. Is WASM ignoring preprocessor commands for certain variables or am I missing something? For now, I am resorting to using externs in my source files, but that is really annoying. Any thoughts on how to address this?
The guard you added (ifndef / define or #pragma once) works as expected. They will prevent your compiler to include this more than once in the same compilation unit. So, if you include this header in several cpp file (different compilation unit), this header will be included several times and your variable will be duplicated.
To solve that, you should :
Keep guards in your code, this is a good habbit
Add the “external” keyword before your global declaration
external bool WPSent;
In one of your cpp, “module.cpp” for instance, declare and initialize your global variable
bool WPSent = false;
You can now include your header in any cpp file you have.
I understand, but I have to admit I am still confused about your answer. These compiler guards work well and are a standard practice when including the same header file in several .cpp files (different compilation units)… that is their purpose. And, they work when compiled with the standard VS compiler. So, there must be something different between VS compiler and WASM compiler. The code I have is a module I used in P3D, compiled as DLL, and it compiled without any errors, so I was a bit concerned when it produced errors in WASM.
Sure - I know how to fix it (I’ll probably go with declaring all vars static) but I was wondering why is WASM “complaining” about this, and the standard VS is not?