Sergey U
Sergey U

Reputation: 37

How do I check if precompiled headers are really used?

As such possibility is stated in gcc documentation https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html I have folder with precompilded headers, name it all.h.gch. It contains several precompiled headers like all1.h.gch, all2.h.gch, etc, each compiled for different set of defines. I build them with separate makefile each.

After that, I build my project, name it test, with its own makefile. I specify pch folder with -I option: -I/path/to/all.h.gch

According to link above, compiler should automatically pick suitable header from all.h.gch folder.

How do I check if it really uses precompiled header instead of compile all.h each time anew? Measuring compile time using 'time' utility is not an option, because compile time is too small to notice difference.

Upvotes: 2

Views: 460

Answers (2)

Jarod42
Jarod42

Reputation: 218323

You might use -H option to manually check which header is used. Emphasis mine:

-H

Print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the ‘#include’ stack it is. Precompiled header files are also printed, even if they are found to be invalid; an invalid precompiled header file is printed with ‘...x’ and a valid one with ‘...!’.

Upvotes: 4

HolyBlackCat
HolyBlackCat

Reputation: 96951

Not what you asked for, but I wouldn't rely on #include picking up PCHs, because Clang doesn't do this (and it's a good idea to have a build process compatible with both GCC and Clang).

Instead, include the PCH header via a flag: -include path/to/header.h.

To be certain that the PCH actually gets used (and to be able to switch between different versions of the PCH with different flags), you can put header.h.gch into a different directory (away from the original header.h), then only pass the path to .gch to -include (but without the .gch extension).

Upvotes: 3

Related Questions