I have the following problem: My (C++-)project consists of several subprojects. In each, I have several files with code I want to run at startup. My solution so far is to use static variables which call the respective code on initialization like this:
// Foo.cpp
static TFooRegistry sFooRegistry; // does stuff in constructor.
When building my project using dlls for each subproject, everything works fine and the code runs as expected. When linking the subprojects statically, however, the linker determines that Foo.o contains no code ever referenced from outside and optimizes it away. Of course I could add a reference to sFooRegistry somewhere else, but this is tedious and error prone.
What (standard conformant) ways of solving this are there?
OK, what can I do on mac/gcc and win/visual studio?