1

https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html lists the preconditions that need to be satisfied for a precompiled header to be usable with a given compiler invocation.

In short it's:

  1. same compiler binary
  2. same -m -f -p -O options with exceptions for: -fmessage-lenght= -fpreprocessed -fsched-interblock -fsched-spec -fsched-spec-load -fsched-spec-load-dangerous -fsched-verbose=number -fschedule-insns -fvisibility= -pedantic-errors

  3. -g at least if the compilation is with -g (=> pchs should always be compiled with -g)

I'm curious if I could manage this automatically for an arbitrary option set.

The idea is I could run my gcc invocation through a wrapper that would extract from it information about the compiler binary and the -m -f -p -O options, form a filepath for the compiled header based on this info, check if a precompiled header is already in there and if not create it, prepend the header's directory to the preprocessor's iquote or isystem search path, and run the actual wrapped gcc invocation.

Is there a better approach? If not, is there a way for me to extract the gcc options without having to keep in sync with the documented gcc option set?

Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • Possible duplicate of [Creating several precompiled header files using GNU make](https://stackoverflow.com/questions/4482740/creating-several-precompiled-header-files-using-gnu-make) – anatolyg Jul 16 '17 at 11:26
  • I am not sure the linked question does exactly what you want; anyway, the best answer to it is in a [comment](https://stackoverflow.com/questions/4482740/creating-several-precompiled-header-files-using-gnu-make#comment5150161_4482740); otherwise, please clarify what exactly you are trying to do. – anatolyg Jul 16 '17 at 11:27
  • @anatolyg I was looking for a more robust solution where the user of a big header wouldn't have to manage the compiled versions manually, but I guess I'll settle for manual management with the help of -Winvalid-pch for now, although I'd rather keep the question open. Thanks for the help. – Petr Skocik Jul 16 '17 at 11:36

0 Answers0