How to use extern for sharing variables between files in C++?
Greetings! I'm a beginner C++ developer and I've encountered a problem: I have a project consisting of several files, and I need to use a shared variable in different .cpp files. I tried declaring a variable in one file and using it in another, but the compiler gives an "undefined reference" or "multiple definition" error.\n\nHere's a simplified example: I have a file `main.cpp`:\n\n```cpp\n#include \n#include "functions.h"\n\nint main() {\n global_var = 5;\n print_var();\n return 0;\n}\n```\n\nFile `functions.h`:\n\n```cpp\n#ifndef FUNCTIONS_H\n#define FUNCTIONS_H\n\nint global_var; // variable declaration\n\nvoid print_var();\n\n#endif\n```\n\nAnd `functions.cpp`:\n\n```cpp\n#include \n#include "functions.h"\n\nvoid print_var() {\n std::cout << "globa