[Bug c++/54780] New: G++ does not find precompiled headers in some cases

jpakkane at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Oct 2 13:23:00 GMT 2012


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.



More information about the Gcc-bugs mailing list