Oh right, I overlooked that mistake.
Doing
in a header file is wrong, because it defines / creates these global variables. So every .cpp
file that includes this header will, when compiled, want to create the shown global variables. If more than one does that, you have a double definition.
The way to solve that is to declare these global variables as extern
in the header and then only define them in one .cpp
file, so that only one instance of the global variable is created, but everyone that includes the headers knows about the existance of these variables (= declaration). Change the header file to
//global var:
extern float xAccel, yAccel, zAccel;
extern float xMeas, yMeas, zMeas;
extern int KXTJ3;
and add in one .cpp
file of your choice the original expression
float xAccel, yAccel, zAccel;
float xMeas, yMeas, zMeas;
int KXTJ3 = 0x0E;
See c++ - How do I use extern to share variables between source files? - Stack Overflow for reference.
The include guards only guard against multiple inclusions of the same file in one compilation unit (= one .cpp file), it does not prevent anything in regards to a second compilation unit, they’re all stand-alone until the linking phase.