ccache can't use precompiled header

• Mar 19, 2017 - 03:33

I'm on a fresh arch linux install, and setup qtcreator use ccache compiler wrapper. But ccache isn't reusing previously compiled files, and according to the ccache stats, it says 769 files that have been compiled "can't use precompiled header":

[e@V12 ~]$ ccache -s
cache directory                     /home/e/.ccache
primary config                      /home/e/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                           223
cache hit rate                      0.00 %
called for link                       35
called for preprocessing             104
can't use precompiled header         769
no input file                         31
cleanups performed                    30
files in cache                       381
cache size                          35.9 MB
max cache size                       5.0 GB

According to https://ccache.samba.org/manual.html#_precompiled_headers:

ccache has support for GCC’s precompiled headers. However, you have to do some things to make it work properly:

You must set sloppiness to pch_defines,time_macros. The reason is that ccache can’t tell whether __TIME__ or __DATE__ is used when using a precompiled header. Further, it can’t detect changes in #defines in the source code because of how preprocessing works in combination with precompiled headers.

You must either:

use the -include compiler option to include the precompiled header (i.e., don’t use #include in the source code to include the header); or

(for the Clang compiler) use the -include-pch compiler option to include the PCH file generated from the precompiled header; or

add the -fpch-preprocess compiler option when compiling.

If you don’t do this, either the non-precompiled version of the header file will be used (if available) or ccache will fall back to running the real compiler and increase the statistics counter “preprocessor error” (if the non-precompiled header file is not available).

So if anyone has an idea why musescore's precompiled headers aren't working, let me know.


Comments

Hi, I remember having the same problems with ccache some time ago. I gave up on this, so if you find a solution, let me know, please.

I once managed to have ccache working under Windows by defining the environmental variable:
CCACHE_SLOPPINESS=pch_defines,time_macros
as stated in the manual, but then I did not find a real improvement in the compilation.

In reply to by ABL

Thanks...I got an error ccache: error: SLOPPINESS: unknown sloppiness: "time_macros", but it seems that if I removed time_macros it is able to compile. I'll have to check my ccache stats in about a week to know whether I have had any success.

Note: it will only improve compilation for .cpp files that already was compiled with identical headers. So I only imagine it being useful for things like modifying a header file in a feature branch and then checking out old master.

In reply to by ericfontainejazz

Looks like I'm getting hits in ccache now! That means it's working! Thanks!

[e@V12 ~]$ ccache -s
cache directory                     /home/e/.ccache
primary config                      /home/e/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
cache hit (direct)                    31
cache hit (preprocessed)               4
cache miss                           293
cache hit rate                     10.67 %
called for link                       60
called for preprocessing             192
preprocessor error                     4
can't use precompiled header        1795
bad compiler arguments                 6
autoconf compile/link                 22
no input file                         63
cleanups performed                    31
files in cache                       541
cache size                         233.5 MB
max cache size                       5.0 GB

In reply to by ericfontainejazz

For information purposes I'm making a note that the ccache is apparently working for me on arch linux. I had built master and then checked out 2.1 and built it, and then checked stats:

[e@V12 ~]$ ccache -s
cache directory                     /home/e/.ccache
primary config                      /home/e/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
cache hit (direct)                    51
cache hit (preprocessed)               8
cache miss                          1732
cache hit rate                      3.29 %
called for link                      250
called for preprocessing             266
compile failed                         2
preprocessor error                     5
can't use precompiled header        3092
bad compiler arguments                 6
autoconf compile/link                 22
no input file                         71
cleanups performed                    31
files in cache                      3414
cache size                           1.2 GB
max cache size                       5.0 GB

And then I checked out master again, re-built it, and then checked stats:

[e@V12 ~]$ ccache -s
cache directory                     /home/e/.ccache
primary config                      /home/e/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
cache hit (direct)                    54
cache hit (preprocessed)             129
cache miss                          1736
cache hit rate                      9.54 %
called for link                      251
called for preprocessing             273
compile failed                         2
preprocessor error                     5
can't use precompiled header        3524
bad compiler arguments                 6
autoconf compile/link                 22
no input file                         71
cleanups performed                    31
files in cache                      3543
cache size                           1.2 GB
max cache size                       5.0 GB

If you notice, the "cache miss" value increased from 1732 to only 1736. So that means it only had to compile 4 files when switching back to master from 2.1, and I also noticed that the recompile was much faster.

In reply to by ericfontainejazz

I'm noting that whenever I checkout 2.1 from master, that ccache doesn't work for anything in the mscore directory because:

cc1plus: warning: /home/e/MuseScore/build.qtc/all.h.gch: not used because `__STRICT_ANSI__' not defined [-Winvalid-pch]

Although when switching back to master from 2.1, it does seem to take advantage of pch. I'm guessing that 2.1 is not enabled to handle pch. Unless maybe all I need to do is #define __STRICT_ANSI__ or something else?

In reply to by ericfontainejazz

Changing according to that commit in 2.1 seems to allow ccache to work. But now the question is how do I switch between 2.1 and master branches will applying that commit to only 2.1, but not having that commit get in pull requests made for 2.1...these are the types of git questions which I can never resolve, even after an hour on stackexchange.

Do you still have an unanswered question? Please log in first to post your question.