强行收录header未找到

Forcibly included header not found

我正在尝试在使用 GCC 5.4 编译的大型 C++ 项目中设置预编译 headers。

有一个文件 "PrecompiledHeaders.h",其中包括所有其他相关的 header。我已经添加了编译标志 -include PrecompiledHeaders.h,但是在编译时,找不到 header:

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

但我确定它存在,与所有其他 hcpp 文件位于同一目录中。更重要的是,手动将 #include "PrecompiledHeaders.h" 添加到 "NetworkGameState.cpp" 的顶部不会产生错误。 会出什么问题?

顺便说一下,这是一个 CMake,out-of-source 构建。

可能是路径有问题。来自 the GCC 5.4 manual(强调我的):

-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.

您需要提供 header 的完整(相对或绝对)路径作为 -include 标志的参数,或者将其 parent 目录添加到搜索链使用例如-I-iquote.