https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100462

--- Comment #6 from Marco Trevisan <mail at 3v1n0 dot net> ---
(In reply to Jakub Jelinek from comment #5)
> As documented - see
> https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html - PCH is only
> tried if no C token is seen before the #include directive (comments and
> preprocessor directives like #if/#ifdef/#define/#undef are fine, but e.g.
> #pragma is not).
> So, is #include "gjs_pch.hh" the first thing in your sources?

Well it's not because I instead was following the approach of

> This also works with -include. So yet another way to use precompiled headers, 
> good for projects not designed with precompiled header files in mind, is to 
> simply take most of the header files used by a project, include them from 
> another header file, precompile that header file, and -include the 
> precompiled header. If the header files have guards against multiple 
> inclusion, they are skipped because they’ve already been included (in the 
> precompiled header). 


Thus, `-include` is ignored here it seems... Because it comes after another
include...

As per this I think the minimal reproducer is actually easy to have:

// main.c
int main(int argc, char**argv)
{
  std::string s = "Hi";
  return 0;
}

// header.h
#include <string>

----

mkdir _build
g++ -c header.h -o _build/gjs_pch.h.gch

# Works
g++ -I _build main.c -o main -include string -include gjs_pch.h

# Fails
g++ -I _build main.c -o main -include string -include gjs_pch.h


cc1plus: fatal error: gjs_pch.h: No such file or directory

So, in this case I'm not sure that the pch should be ignored...

Reply via email to