How to use .h.gch files
c, c++, gcc, header-files, precompiled-headers
Solution
Using GCH (Gnu preCompiled Headers) is easy, at least in theory.
How to create a GCH
Just use `gcc <compiler-options> myfile.h`. That will create `myfile.h.gch`. You can use the `-o <name>` to specify the name of the output file.
If your header file is C++, you will have to name it `myfile.hpp` or `myfile.hh`, or GCC will try to compile it as C and probably fail. Alternatively you can use the `-x c++-header` compiler option.
How to use a GCH
Put your `myfile.h.gch` in the same directory than `myfile.h`. Then it will be used automatically instead of `myfile.h`, at least as long as the compiler options are the same.
If you do not want to (or can) to put your `*.gch` in the same directory of your `*.h`, you can move them to a directory, say `./gch`, and add the option `-Igch` to your compiler command.
How to know your GCH is being used
Use `gcc -H <compiler-options> myfile.c`. That will list the included files. If your `myfile.h.gch` does not appear, or has an `x`, then something is wrong. If it appears with a `!`, congratulations! You are using it.
Problem
I recently found out about precompiled headers in `C++`, specifically for `gcc` compilers. I did find something about the `.h.gch` files on the net, but haven't yet been able to use them. I need to know: - How to create a `.h.gch` file? My code isn't creating one? - Once created, how to use it? do you include it like any other user-defined file? ex: `#include "SomeCode.h.gch"` Or is there some other way of using it? please help