c++static

How do I get Visual Studio's compiler to NOT ignore files that I haven't included anywhere (but are in my project)


I have written a system that registers metadata for a class when initiating a static bool.

For example :

   bool CreateMetaDataForTestClass() {
     // Registration of metadata
   }

   static bool initBoolForTestClass = CreateMetaDataForTestClass();

The system works great.

There is a problem, however. I can create classes using strings from config files. If I have a situation where a class I want to use is never included in any files, the compiler seems to ignore the files, and consequently NOT initiate my static variable and not register my class.

If I'm lucky - Is there a compiler switch that solves this problem?

I would like to NOT have to include those files, as it is kind of the point of the system - to have zero integration with the engine as the class registers itself automatically.


Solution

  • At some point you need to tell the system which classes are available. If you want to have a statically linked executable, you will have to specify all object files linked into the executable. When you want to specify the available classes only at run time you will need to provide some sort of configuration (e.g. by searching a particular directory or a file listing the objects) for shared objects your program needs to load. It won't just be magically there.