Reputation: 99
I have a function defined in file1.h
as below:
/** file1.h **/
def testFunc(){}
file1.h is written once and will not be modified during the development. But I have to use testFunc()
in my code say in file2
.
/** file2.h **/
#include "file1.h"
testFunc(); //some sort of use
The problem is every time I make a change to file2.h
, the compiler obviously also compiles file1.h
, which takes time. Any suggestion on how to stop the compiler from compiling the file every time?
Upvotes: 0
Views: 574
Reputation: 29975
You can use precompiled headers as a solution. How you do that depends on your Compiler and environment. Here is a start for GCC:
To create a precompiled header file, simply compile it as you would any other file, if necessary using the -x option to make the driver treat it as a C or C++ header file. You may want to use a tool like
make
to keep the precompiled header up-to-date when the headers it contains change.A precompiled header file is searched for when
#include
is seen in the compilation. As it searches for the included file (see Search Path in The C Preprocessor) the compiler looks for a precompiled header in each directory just before it looks for the include file in that directory. The name searched for is the name specified in the#include
with ‘.gch’ appended. If the precompiled header file cannot be used, it is ignored.
Upvotes: 2