Question

I have a bunch of cpp files (there should be no header files) that contain static variables. These static variables seem to be ignored by my Visual studio 2008 compiler - how can I fix it?

More details:

  • I have an abstract class that has a static field allInstances; when an "concretee" instance of my class is constructed (it happens when static variables that sit in cpp files are instantiated), a pointer to it is push_back'ed into allInstances.
  • Cpp files contain the classes derived from my abstract class; their implementations need to stay in cpp files as they are only meant to be called through allInstances
  • My abstract class cpp files sit in a folder (project) that compiles in a static library
  • This static library is used by a project that compiles an xll

When cpp files were sitting in xll project, everything was fine. But when I moved cpp files in a separate folder (needed to be done because excel is now not the only interface) my static variables are no longer instantiated.

I have a lot of these cpp files and including all of them into each of xll, exe, pyd, dll, etc. projects would not be nice....

Any ideas? Many thanks in advance.

Was it helpful?

Solution

You have to tell the linker that the corresponding object files are part of the program. Typically, this is done by specifying them as object files, rather than by putting them in a library; by definition, object files in a library only become part of the program if they resolve an external reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top