I’m trying to use the g2log logging library inside my DLL project using VS2012.
The problem is that looking at the documentation LINK」 it needs to be initialized at the beginning and stay alive for the lifespan of the program.
Since I don’t have a main, and using DllMain doesn’t help, where could I do the initialization?
(I started this project recently so I also accept suggestions about other options for a logging library)
As you are using VS2012 you can use C++11 which means you can have thread-safe statics so you can add a global function:
And then use that get_logg() to get hold of the object (if you need more elaborate construction/initialization you can also do that inside this function using std::atomic<> from C++11). Here is a version using std::atomic_flag:
I do not use or know the g2log library so I cannot give more explicit examples.