The Samba-Bugzilla – Bug 8703
ccache fails to compile pre-compiled headers
Last modified: 2012-08-11 13:26:37 UTC
ccache is not handling pre-compiled headers properly with gcc-4.1.2.
devaus120>> cat test.hxx
devaus120>> g++ -xc++-header test.hxx
devaus120>> d test.*
-rw-r--r-- 1 ssmedley ss 38 Jan 16 16:33 test.hxx
-rw-r--r-- 1 ssmedley ss 1.1M Jan 16 16:33 test.hxx.gch
devaus120>> ccache g++ -xc++-header test.hxx
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
devaus120>> ccache -V
ccache version 3.1.7
Copyright (C) 2002-2007 Andrew Tridgell
Copyright (C) 2009-2011 Joel Rosdahl
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
devaus120>> uname -a
Linux DEVAUS120 2.6.18-194.17.1.el5 #1 SMP Wed Sep 29 12:51:33 EDT 2010 i686 athlon i386 GNU/Linux
devaus120>> g++ -dumpversion
Interestingly, passing -c flag makes it work!
But why does g++ only need -c when used with ccache?
For that invocation, ccache runs something like this under the hood:
/usr/bin/g++ -x c++-header -o a.temporary.file test.hxx
Apparently, g++ 4.1 doesn't like the split of -xc++-header into two arguments:
% g++ -x c++-header test.hxx
/usr/lib/crt0.o: In function `___start':
: undefined reference to `main'
As you mentioned, adding -c also makes it work. g++ 4.3 and newer work fine regardless.
I could perhaps make ccache use -xc++-header, but that feels kind of silly since it's not documented that way. Adding -c doesn't feel right either. Sigh.
Fixed in 4520fd7cb0bb01eea00b6fd57f40c174a0c4e6be.
Fix included in v3.1.8.