In one of your source files, you need to declare and define the variable in file-scope, outside of any functions. For example:
int foo;
In the other source files you just need to declare the variable (no definition):
extern int foo;
The easiest way is to put the extern in a some common header file which is included in your other source files.
Since you're using C++, I would recommend encapsulating the variable inside a namespace, at the very least.
Reference from:http://forums.whirlpool.net.au/archive/745569