I'm working on a C++ library that I would ideally keep header-only.
A specific part of this library requires a global state.
Let's say it needs a global vector of strings for this example.
I can easily achieve this with a static
variable inside a function:
std::vector< std::string > & GetGlobalStrings( void )
{
static auto g = new std::vector< std::string >();
return *( g );
}
This works great for executables using the library.
Now for some reason, I also need to package that library inside a macOS framework.
Inside that framework, there's compiled code that will access this global state.
So does the executable linked with that framework.
Obviously this doesn't work, as the executable and the framework will have separate definitions for the static variable, thus making this global state not so global.
Is there any way to accomplish this in a convenient manner?