6

I am using ccache for experiments, but I am not quite sure that I should use this. Can anyone explain the situation when ccache can result in wrong behavior. Or should we always use ccache ? Anyone who got that ccache is producing wrong object files or changes in header files are not being considered ?

peeyush
  • 2,841
  • 3
  • 24
  • 43
  • 3
    http://ccache.samba.org/ says that there shouldn't be any wrong behavior, and that if someone knows of one, he should report it instead of answering questions on StackOverflow. – Pascal Cuoq Dec 18 '11 at 18:51
  • absolutely. thanks, I should use updated ccache and keep looking for existing reported bugs which are not being handled to stay aware of might-be bug. – peeyush Dec 18 '11 at 19:15

3 Answers3

9

I practically never have any issues while using ccache. Sometimes (e.g. once a month or even less), I clean entirely its cache with ccache -C.

I have more issues with complex Makefile-s than with ccache.

To be short, don't bother, and when you suspect something, just run ccache -C.

You obviously should avoid ccache when you are benchmarking the compilation time. (You could pass -time or -ftime-report to gcc or g++ in that case).

Addenda

I my opinion, ccache should be at least configurable to disable caching for compilation using GCC plugins, because a GCC plugin could do anything (e.g. querying a database or webservice) which is not cachable. See this message.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • thanks for suggestion... :-). btw what the situations when you get issues sometimes ? because when we get issues it is difficult to get clue that it's coming because of ccache. and also when you get issues, "ccache -c" is the absolute solution, then there must be some problem with ccache. – peeyush Dec 18 '11 at 20:09
  • 1
    No, I strongly suspect the hypothetical issues to be in Makefile-s. In MELT http://gcc-melt.org/ my Makefile-s are buggy (and GCC Makefile-s are perhaps incomplete also for partial rebuilds). Again, I never suspected ccache of doing wrong. – Basile Starynkevitch Dec 18 '11 at 20:14
  • `ccache` being usually fired as `gcc` if a bad `Makefile` forgets to run a compilation command, with or without `ccache` you get in trouble. – Basile Starynkevitch Dec 18 '11 at 20:58
4

You phrased your question well by asking wrong behavior.

The wrong behavior ccache may have is slowing down your compilation if used incorrectly. ccache has to scan the file to recognize past compilations, so an actual compilation through ccache is slower than without it. Only a cache hit is faster.

ccache is useful when you frequently recompile the same code without modifying it. It will not speed up compilation of new or modified code.

Offirmo
  • 18,962
  • 12
  • 76
  • 97
3

I once had issues with SCons compiling through ccache (symlink method).

Environment Settings

It turned out ccache requires the $HOME variable to be set in the environment, whereas SCons doesn't set it by default (SCons has the policy to isolate builds from the environment as much as possible by default).

I'm not entirely sure whether this would count as a problem with ccache or merely interoperating with SCons. Besides this quirk, I never had any trouble with ccache.

SSD wear

I have adopted the habit of linking ~/.ccache to tmpfs to avoid wearing my SSDs unnecessarily. Obviously, this is not a problem with ccache, because without it, things would be worse still. (Just something to keep in mind)

sehe
  • 374,641
  • 47
  • 450
  • 633