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

            Bug ID: 57242
           Summary: gcc ignores precompiled headers unless the .gch and
                    TU's are compiled with certain combinations of -g flag
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: pch
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scottbaldwin at gmail dot com

In GCC 4.7.2 and 4.8.x, precompiled headers (PCH) .gch file is ignored unless a
certain combination of '-gN' debug options are used.
To demonstrate, consider the following g++ commands to generate PCH
(my_pch.hpp.gch) and compile a TU (foo.cpp) using the PCH cache:

g++ $(PCH_DEBUG_FLAGS) -std=c++11 -m64 -Wall -Werror -Wno-unused
-Wno-unused-variable -I./dbg-mt -I. -I. ./dbg-mt/my_pch.hpp -o
./dbg-mt/my_pch.hpp.gch
g++ $(CPP_DEBUG_FLAGS) -std=c++11 -m64 -Wall -Werror -Wno-unused
-Wno-unused-variable -I./dbg-mt -I. -I. -c foo.cpp -o dbg-mt/foo.o

The only difference between these two commands (other than the input file) is
the $(PCH_DEBUG_FLAGS) vs $(CPP_DEBUG_FLAGS).

However, in order for the precompiled headers (.gch file) to be used when
compiling the source files (e.g., foo.cpp), both of the following conditions
must be met:
  1) The '-g' or '-g2' or '-g3' flag must be used when building the precompiled
headers (.gch file).
  2) The '-g3' flag (and no less) must be used when compiling each TU (.c/.cpp
file), and

In other words:
  PCH_DEBUG_FLAGS = -g3 or -g2 or -g (specifying no 'g' at all will cause PCH
cache to be ignored)
  CPP_DEBUG_FLAGS = -g3 (specifying -g2 or -g or no 'g' at all will cause PCH
cache to be ignored)

I put a #warning in the my_pch.hpp file to be sure of when PCH were being
ignored (though, the long delay also made it quite obvious).

This bug is present in all 3 versions of gcc I tested (4.7.2, 4.8.0,
4.8.1_20130427).

Reply via email to