I just build a simple C++ project. The codes are shown in the follows:
-------- head.h --------
#ifndef _HEAD_H_
#define _HEAD_H_
int my_var = 100;
#en
Change the header the following way
#ifndef _HEAD_H_
#define _HEAD_H_
extern int my_var;
#endif
And for example add line in the module with main
#include "head.h"
int my_var = 100;
int main() { return 0; }
The problem is that as the header is included in two modules then each module contains a variable with external linkage with the same name as a variable in other module. And the linker does not know which variable to use.