public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54780] New: G++ does not find precompiled headers in some cases
@ 2012-10-02 13:23 jpakkane at gmail dot com
  2012-10-02 13:53 ` [Bug c++/54780] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jpakkane at gmail dot com @ 2012-10-02 13:23 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54780

             Bug #: 54780
           Summary: G++ does not find precompiled headers in some cases
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jpakkane@gmail.com


Created attachment 28326
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28326
Some dummy sources demonstrating the issue

Using GCC of Ubuntu Quantal, version gcc version 4.7.2 (Ubuntu/Linaro
4.7.2-2ubuntu1).

Under some circumstances g++ does not find precompiled headers that are in the
search path.

I have attached a simple test case that demonstrates the issue. Just run
compile.sh that comes with it and watch the output.

In the test case there is a common.h header that includes a bunch of STL
headers. It is in a subdirectory called hdir. The file is first precompiled and
placed in the subdirectory pchdir.

The script then compiles a bunch of files that include common.h but do very
little else. Both pchdir and hdir are passed in with -I. The precompiled header
is found and compilation is fast.

Next the script copies common.h to the main directory and compiles the sources
again using the exact same compiler switches. What happens is that g++ does not
find the precompiled header, probably because it first looks in the source dir
and finds common.h but not the corresponding pch and just stops looking. This
makes the compilation very slow.

Then the script copies the precompiled header to the main directory and
compiles the files again. Now g++ finds the pch and compilation is again fast.

Summing all this up: precompiled headers can not be used if the header is in
the source directory and the pch is in some other directory which is included
with -I. This is a problem when doing out-of-source builds.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/54780] G++ does not find precompiled headers in some cases
  2012-10-02 13:23 [Bug c++/54780] New: G++ does not find precompiled headers in some cases jpakkane at gmail dot com
@ 2012-10-02 13:53 ` redi at gcc dot gnu.org
  2012-10-02 17:53 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-02 13:53 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54780

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-02 13:53:13 UTC ---
(In reply to comment #0)
> Next the script copies common.h to the main directory and compiles the sources
> again using the exact same compiler switches. What happens is that g++ does not
> find the precompiled header, probably because it first looks in the source dir
> and finds common.h but not the corresponding pch and just stops looking. This
> makes the compilation very slow.

This is by design.  A header included as #include "common.h" looks in the
current dir first, so the compiler looks for ./common.h.gch, then for
./common.h, then stops because it's found.  The alternative would be to
continue searching *every* other directory looking for common.h.gch, which
would be *much* slower (there might be no PCH anywhere, so for projects that
don't use PCH it would mean checking every single directory for every single
header)

Maybe the solution you want is to use #include <common.h> and add -I. to the
compilation commands, ensuring that -Ipchdir comes before -I. because that will
not start with the current dir, and will look for pchdir/common.h.gch first and
will stop when found. Doing that makes all three steps in your script very
fast.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/54780] G++ does not find precompiled headers in some cases
  2012-10-02 13:23 [Bug c++/54780] New: G++ does not find precompiled headers in some cases jpakkane at gmail dot com
  2012-10-02 13:53 ` [Bug c++/54780] " redi at gcc dot gnu.org
@ 2012-10-02 17:53 ` pinskia at gcc dot gnu.org
  2012-10-03  7:54 ` jpakkane at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-10-02 17:53 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54780

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-10-02 17:53:40 UTC ---
This sounds like the reason why some people want back -I- .


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/54780] G++ does not find precompiled headers in some cases
  2012-10-02 13:23 [Bug c++/54780] New: G++ does not find precompiled headers in some cases jpakkane at gmail dot com
  2012-10-02 13:53 ` [Bug c++/54780] " redi at gcc dot gnu.org
  2012-10-02 17:53 ` pinskia at gcc dot gnu.org
@ 2012-10-03  7:54 ` jpakkane at gmail dot com
  2012-10-03  9:00 ` redi at gcc dot gnu.org
  2012-10-03 13:10 ` schwab@linux-m68k.org
  4 siblings, 0 replies; 6+ messages in thread
From: jpakkane at gmail dot com @ 2012-10-03  7:54 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54780

--- Comment #3 from jpakkane at gmail dot com 2012-10-03 07:53:59 UTC ---
Thanks for the explanation and workaround.

I guess this is not a big issue if you are using Autotools, where the
established practice is to compile inside the source directory. It might cause
a lot of head scratching for users of other build systems or those few
autotools users that use a dedicated build directory.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/54780] G++ does not find precompiled headers in some cases
  2012-10-02 13:23 [Bug c++/54780] New: G++ does not find precompiled headers in some cases jpakkane at gmail dot com
                   ` (2 preceding siblings ...)
  2012-10-03  7:54 ` jpakkane at gmail dot com
@ 2012-10-03  9:00 ` redi at gcc dot gnu.org
  2012-10-03 13:10 ` schwab@linux-m68k.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-03  9:00 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54780

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-03 09:00:05 UTC ---
I think the majority don't use PCH anyway.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/54780] G++ does not find precompiled headers in some cases
  2012-10-02 13:23 [Bug c++/54780] New: G++ does not find precompiled headers in some cases jpakkane at gmail dot com
                   ` (3 preceding siblings ...)
  2012-10-03  9:00 ` redi at gcc dot gnu.org
@ 2012-10-03 13:10 ` schwab@linux-m68k.org
  4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2012-10-03 13:10 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54780

--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> 2012-10-03 13:10:32 UTC ---
> I guess this is not a big issue if you are using Autotools, where the
> established practice is to compile inside the source directory.

It is common practice to build outside the source directory, since it is very
well supported.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-10-03 13:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-02 13:23 [Bug c++/54780] New: G++ does not find precompiled headers in some cases jpakkane at gmail dot com
2012-10-02 13:53 ` [Bug c++/54780] " redi at gcc dot gnu.org
2012-10-02 17:53 ` pinskia at gcc dot gnu.org
2012-10-03  7:54 ` jpakkane at gmail dot com
2012-10-03  9:00 ` redi at gcc dot gnu.org
2012-10-03 13:10 ` schwab@linux-m68k.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).