I want to decrease the size of .obj files in a large project I’m working on (I know that linker removes duplicate definitions, but I want to speed up the build process). One of the reasons for their size is that each class which uses std::vector<double> or std::vector<std::string> ends up compiling the code of this class and placing it in its .obj file. I tried to explicitly instantiate std::vector<double> and use extern template declaration, but it doesn’t work — std::vector in Visual Studio C++ STL has all methods inline. Short of modifying the STL code (which I won’t do), is there any way to force the compiler not to inline instantiated methods and to use the externally instantiated version of std::vector<double>?
I want to decrease the size of .obj files in a large project I’m
Share
The only thing that comes to mind is writing an inclusion header that defines the
std::vectortemplate (but not its members, those only need to be declared) and include that instead of thevectorstandard header.Then you can explicitly instantiate
std::vector<whatever>in a separate compilation unit and link against that.To explicitly instantiate the template, don’t use
extern template(that won’t work), just use the following: