Avoid embedding excretedly generated std :: vector <T> code? (Visual Studio C ++ 2008)
I want to reduce the size of .obj files in a large project I'm working on (I know that the linker removes duplicate definitions, but I want to speed up the build process). One reason for their size is that every class that uses std::vector<double>or std::vector<std::string>finishes compiling the code for that class and puts it in its .obj file. I tried to explicitly create an instance std::vector<double>and use the declaration extern template, but this will not work - std::vectorin Visual Studio C ++ STL has all inline methods. If you do not change the STL code (which I will not do), is there a way to force the compiler not to create built-in methods and use an instance created from the outside std::vector<double>?
The only thing that comes to mind is to write an inclusion header, which defines the template std::vector(but not its members, which should be declared only), and include this instead of the standard header vector.
Then you can explicitly create an instance std::vector<whatever>in a separate compilation unit and link to it.
To explicitly create an instance of the template, do not use extern template(this does not work), just use the following:
#include <vector> // The standard header, not your forward-declaration!
template class std::vector<double>;