简体   繁体   English

找不到强制包含的标题

[英]Forcibly included header not found

I'm trying to set up precompiled headers in a large C++ project compiled with GCC 5.4. 我试图在使用GCC 5.4编译的大型C ++项目中设置预编译头。

There is a file "PrecompiledHeaders.h", which includes all the other relevant headers. 有一个文件“ PrecompiledHeaders.h”,其中包括所有其他相关的头文件。 I've added the compile flag -include PrecompiledHeaders.h , but when compiling, the header is not found: 我添加了编译标志-include PrecompiledHeaders.h ,但是在编译时,找不到标头:

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. 但我确定它与所有其他hcpp文件位于同一目录中。 What's more, manually adding #include "PrecompiledHeaders.h" to the top of "NetworkGameState.cpp" does not produce an error. 此外,手动将#include "PrecompiledHeaders.h"添加到“ NetworkGameState.cpp”的顶部不会产生错误。 What could go wrong? 可能出什么问题了?

This is a CMake, out-of-source build, by the way. 顺便说一下,这是一个CMake的源代码外生成。

It's likely an issue with the path. 路径可能有问题。 From the GCC 5.4 manual (emphasis mine): GCC 5.4手册 (重点是我的):

-include file -include 文件
Process file as if #include "file" appeared as the first line of the primary source file. 处理文件时 ,好像#include "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. 如果未在此处找到,则照常在#include "..."搜索链的其余部分中进行搜索。

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 eg -I or -iquote . 您需要提供标头的完整(相对或绝对)路径作为-include标志的参数,或者使用-I-iquote将其父目录添加到搜索链中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM