Firstly, I did not use pch with gcc only with microsoft compiler.
#Ifdef conditions, etc. all are allowed before compilation, so if you change the preprocessor variable, the PCH file will be compiled. So just add all the files from the library that you need.
Generally speaking, include all headers that are unlikely to change often (i.e. external libraries and parts of your system that are stable).
Don't worry about including headers several times in your pch file. Since this file will not be compiled very often, you can ignore the long compilation time here.
What I'm not sure is if the execcutable file size increases when you include everything in your pch file. This may be because you are referencing other unused parts of the code that were compiled into your executable file only because you added them to your pch file. You can check it out.
Now, in my experience, another important question: if your compilation is slow when compiling or when linking.
When you have time with a high link, the problem is more likely that you include too many headers in the headers of your code.
This can be optimized by using Forward declarations in header files and including only headers in .cpp files. We had huge monolithic projects, and each time the greatest increase in performance for compilation / linking was by removing header dependencies by declaring as much as possible.
This is because incremental compilation works very well, but incremental compilation does not work.
Here is a brief but good collection of do and don'ts regarding forward declarations: http://www.chromium.org/developers/coding-style/cpp-dos-and-donts
source share