I'm trying to make my game engine supports both static and shared linked modules.

Basically I have a CREATE_MODULE macro that have 2 implementations. This is based on Unreal's method.

#define CREATE_MODULE(Class, Name) \
    static StaticallyLinkedModuleDummy<Class> ModuleDummy##Name(#Name); 
#define CREATE_MODULE(Class, Name) \                                             
    extern "C" AE_DLLEXPORT IModule* InitializeModule() { return new Class(); } 
#endif // !AE_MONOLITHIC

When the build is NOT Monolithic everything works fine, the DLL is loaded by the main function and the InitializeModule is imported and executed.

But when the build is Monolithic the static variable is not always called by the main executable.

Anyone knows how to make sure the compile will always call the static variable's constructor at the beginning of the program?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.