Each translation unit (.c or .cpp file, basically) that includes defines.h will have its own copy of the variable.
I believe declare global extern in title
extern std::string MAINLOG;
and then defining it as a non-static global variable in any of the .c or .cpp files
std::string MAINLOG = "RANDOMNES";
will solve the problem. But this is a bad coding style, IMO. C ++ - a path would be at least a singleton class.
I cannot give meaningful names without knowing the context, but the idea is this:
mainlog.h
class Mainlog { Mainlog() = default;
mainlog.cpp (do not put this in the header!)
Mainlog& Mainlog::instance() { static Mainlog mainlog; return mainlog; }
source share