Bug 8703 - ccache fails to compile pre-compiled headers
Summary: ccache fails to compile pre-compiled headers
Alias: None
Product: ccache
Classification: Unclassified
Component: ccache (show other bugs)
Version: 3.1.7
Hardware: All Linux
: P5 normal
Target Milestone: 3.1.8
Assignee: Joel Rosdahl
QA Contact: Joel Rosdahl
Depends on:
Reported: 2012-01-16 05:45 UTC by scott
Modified: 2012-08-11 13:26 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description scott 2012-01-16 05:45:04 UTC

ccache is not handling pre-compiled headers properly with gcc-4.1.2.

devaus120>> cat test.hxx
class WhoCares
                int x;
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

Comment 1 scott 2012-01-16 05:51:03 UTC
Interestingly, passing -c flag makes it work!

But why does g++ only need -c when used with ccache?
Comment 2 Joel Rosdahl 2012-01-18 22:38:07 UTC
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.
Comment 3 Joel Rosdahl 2012-08-09 13:20:18 UTC
Fixed in 4520fd7cb0bb01eea00b6fd57f40c174a0c4e6be.
Comment 4 Joel Rosdahl 2012-08-11 13:26:37 UTC
Fix included in v3.1.8.