[cfe-users] How to have clang ignore gch directories?

Paul Smith via cfe-users cfe-users at lists.llvm.org
Wed Nov 27 22:06:09 PST 2019


On Thu, 2019-04-25 at 18:53 -0400, Paul Smith via cfe-users wrote:
> On Thu, 2019-04-25 at 14:38 -0700, Richard Smith wrote:
> > > How can I tell clang to just ignore the GCC-specific precompiled
> > > headers, or equivalently ignore precompiled headers altogether?  I
> > > can't delete the gch directories because I need them for my build.
> > > I've read through the clang docs and can't find any likely-looking
> > > options.
> > > 
> > > It's really frustrating when clang tries to appropriate GCC-specific
> > > options and configurations when it's not actually compatible with
> > > them.  It makes modern multi-compiler development so unnecessarily
> > > difficult.
> > 
> > Sorry about that. Clang is trying to be a transparent drop-in
> > replacement for build systems that are designed for GCC, and that
> > means that -include needs to automatically pick up a corresponding
> > .pch / .gch file if a prior build step put one there. Unfortunately
> > we don't do any validation to check whether that's Clang's file or
> > one generated by GCC at that layer :(

Now that CMake 3.16 supports precompiled headers directly, this problem
will only get more and more pronounced as people try to switch to it and
discover it completely breaks their environment.

Of course the built-in CMake support for PCH doesn't try to use the
grotesque hacks that my internal implementation was forced to resort to to
make this work, so I was sad.

So I grabbed a Git clone of the clang source and wrote a patch:
https://bugs.llvm.org/show_bug.cgi?id=41579

I did not try to write a test or anything.  Hopefully someone with some
clang code fu can fix it up to be acceptable and apply it, to stop the
madness.

It may be better to have the code check affirmatively for clang PCH files
instead of ignoring GCC PCH files, but I don't know what the file format
for clang PCH files is and I don't use clang so I didn't try to create one
to find out.




More information about the cfe-users mailing list