Search code examples
c++visual-studio-2008singletonc++-loki

Getting Loki Singleton to work in DLLs in VS 2008 C++


I'm pretty sure this problem isn't new, and pretty sure it's hard to solve. Hopefully I'm wrong about the latter.

I'm trying to use the Loki::Singleton from Modern C++ Design in a program of mine.

However, I can't seem to get it to work across DLLs. I think I know why this is happening: the templated code gets instantiated in every source module, so instead of there being one global variable, each module has its own.

Obviously, this makes the Singleton very much non-single.

Is there any way to get around this behavior?


Solution

  • I see in the Loki source directory that they have a specific SingletonDLL directory under test, looks like they use an exported, explicitly instantiated template (which would work). Hopefully that contains the code you want.