Search code examples
c++makefileg++precompiled-headerspch

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.


Solution

  • 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 ‘...!’.