0

I'm trying to set up precompiled headers in a large C++ project compiled with GCC 5.4.

There is a file "PrecompiledHeaders.h", which includes all the other relevant headers. I've added the compile flag -include PrecompiledHeaders.h, but when compiling, the header is not found:

cc1plus: fatal error: PrecompiledHeaders.h: No such file or directory
compilation terminated.
CMakeFiles/Project.dir/build.make:62: recipe for target 'CMakeFiles/Project.dir/NetworkGameState.cpp.o' failed

But I'm sure it exists, in the same directory as all other h and cpp files. What's more, manually adding #include "PrecompiledHeaders.h" to the top of "NetworkGameState.cpp" does not produce an error. What could go wrong?

This is a CMake, out-of-source build, by the way.

Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301

1 Answers1

1

It's likely an issue with the path. From the GCC 5.4 manual (emphasis mine):

-include file
Process file as if #include "file" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the #include "..." search chain as normal.

You need to either supply the full (relative or absolute) path to the header as the argument of the -include flag, or add its parent directory to the search chain using e.g. -I or -iquote.

You
  • 22,800
  • 3
  • 51
  • 64
  • Ah, I read that, but read it wrong. I thought it would do that first, and then continue with the source file's directory, and the rest. That must be it then – Bart van Heukelom May 18 '17 at 15:06