0
votes

There's a code that includes a lot of standard library headers. The code is situated in one file, and I cannot create any other C++ source files in that project (sic). I would like to increase the performance of the build process using precompiled headers. There're two problems

  1. Trying to use this guide on vector, I've got a file format not recognized error. What flags should I set to show gcc that it's a header file?
  2. There's a quote in official guide that says "Only one precompiled header can be used in a particular compilation". How do I precompile several headers at once then?

(Any batch/shell scripts appreciated too.)

1
one precompiled header can include multiple headers. so you can include all stl headers in one header and use itBryan Chen

1 Answers

0
votes

Didn't you forget to use -x option for compiling your precompiled header as documentation states? Next if you want to have Standard Library's templates precompiled - it's impossible by definition. Using C++11 you can explicitly instantiate some templates in some particular translation unit for certain type arguments. From precompiled header you can specify

extern template void foo<char>(...)

What's the use of precompiled headers if you are trying to use them against templates? Your precompiled header must be a set of other includes/macros definitions/inline functions and everything else that can be safely included into multiple translation units. And yet - only one precompiled header per library/binary.