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:
.h.gch
file?
My code isn't creating one?#include "SomeCode.h.gch"
Or is there some other way of using it? please help
usually you type name-of-your-editor /usr/local/include/name-of your. h . For example vim /usr/local/include/foobar. h .
In computer programming, a precompiled header (PCH) is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler.
Using GCH (Gnu preCompiled Headers) is easy, at least in theory.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With