GCC precompiled headers work in a very specific way. In any source file, only one precompiled header file can be used. Use -H
to indicate whether this header file uses a precompiled version or not.
In addition, you must compile the header file with the same compiler flags as its source file.
A typical way to set up a PCH environment is as follows:
main.cpp:
#include "allheaders.hpp" int main() { }
allheaders.hpp:
#include <algorithm> // ... everything you need
Compilation:
g++ $CXXFLAGS allheaders.hpp
After step 1, you should get the allheaders.hpp.gch
file, which should be quite large. In step 2, the -H
flag should contain additional output that tells you that a precompiled header file is being used. Step 3 links the executable file.
The idea is that step number 1 can take a very long time, but step number 2 should be much faster.
source share