ccache can't use precompiled header
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 I once managed to have ccache 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 Thanks...I got an error by ericfontainejazz
Looks like I'm getting hits in ccache now! That means it's working! Thanks!
In reply to Looks like I'm getting hits 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:
And then I checked out master again, re-built it, and then checked stats:
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 For information purposes I'm 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:
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 I'm noting that whenever I by ericfontainejazz
Which Qt are you using for compilation?
I see in master this commit about pre-compiled headers:
da7a43acbbe2
for Qt >=5.7.
In reply to Which Qt are you using for by ABL
I'm on Qt 5.8...thanks for sharing that commit...I'll try changing that command for my home computer's 2.1 branch.
In reply to I'm on Qt 5.8...thanks for 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.
In reply to Changing according to that by ericfontainejazz
I am definitely not an expert of git, but maybe you can
stash
the change of that commit and apply it on top of the other commits, but without commiting it, so that it is not included in the pull request.See here: http://stackoverflow.com/a/26885183
and here about stash: https://git-scm.com/book/en/v1/Git-Tools-Stashing
I don't know if there is an easier answer.
Ciao,
ABL
In reply to I'm noting that whenever I by ericfontainejazz
Hi @ericfontainejazz,
I am running Manjaro and I had a failing build with these __STRICT_ANSI__ errors in the past. See here:
http://dev-list.musescore.org/problem-building-fonts-td7579951.html
The problem disappeared for me when using gcc instead of gcc-multilib.