C++ How to properly initialize global variables? [duplicate]
问题 This question already has answers here : How do I use extern to share variables between source files? (17 answers) Closed 7 years ago . I'm writing little student project and stuck with the problem that I have a few global variables and need to use it in a few source files, but I get the error *undefined reference to variable_name*. Let's create three source files for example: tst1.h: extern int global_a; void Init(); tst1.cpp: #include "tst1.h" void Init(){ global_a = 1; } tst2.cpp: #include