Due to archaic C++ technology based on header files and its linking, even such trivial thing is not that simple.
If you define (not just declare) a variable in a header file, this declaration will be repeated whenever this file is included, which will be treated as an attempt to create more than one object.
Therefore, the definition should be only one, in a single C file; and in header file it should be referenced as
extern
.
This is discussed in many places. Please see, for example, here:
http://stackoverflow.com/questions/2868651/including-c-header-file-with-lots-of-global-variables[
^].
First of all, I would advise to avoid global variables by all means. If you still need some, I would advise to avoid such situation and rely on classes whenever possible. You can find some sample in one of the answers referenced above.
—SA