Reputation: 7146
Qt has the Q_COREAPP_STARTUP_FUNCTION
macro to register a function to be called as part of the QCoreApplication
constructor. This works fine if used inside an application or a dynamically linked library. However, the function is not executed if used inside a static library.
As far as I understand, that macro creates a static class in whichs constructor the method is passed on to the Qt framework. But since that class isn't used anywhere, the linker simply excludes it when linking the final application.
The question here is: Is my assumption correct? And is there a way to tell the compiler to not exclude such instance? The thing is I don't know if and how many are used, and thus it's impractical to reference them explicitly. Solutions for all compilers (msvc, gcc, clang) are required.
Upvotes: 4
Views: 448