How to prevent the linker from optimizing away startup code?
问题 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