C++ 致命错误 C1083:无法打开包含文件:“xyz.h”:没有这样的文件或目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7789969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fatal error C1083: Cannot open include file: 'xyz.h': No such file or directory?
提问by Apoorva sahay
I am using visual studio 2005 to create a project. And I have folder structure in project as: a folder called code. this folder contains all *.cxx files.
我正在使用 Visual Studio 2005 创建一个项目。我在项目中的文件夹结构为:一个名为 code 的文件夹。此文件夹包含所有 *.cxx 文件。
Now, I have created a class xyz in header file xyz.h. And defined every thing in xyz.cxx which is placed in code folder. But now when I try to compile it with visual studio it throws me an error "fatal error C1083: Cannot open include file: 'xyz.h': No such file or directory". how to rectify this problem.
现在,我在头文件 xyz.h 中创建了一个类 xyz。并在 xyz.cxx 中定义了放置在代码文件夹中的所有内容。但是现在当我尝试使用 Visual Studio 编译它时,它会抛出一个错误“致命错误 C1083:无法打开包含文件:'xyz.h':没有这样的文件或目录”。如何纠正这个问题。
采纳答案by Frank Boyne
Either move the xyz.h file somewhere else so the preprocessor can find it, or else change the #include
statement so the preprocessor finds it where it already is.
要么将 xyz.h 文件移动到其他地方,以便预处理器可以找到它,要么更改#include
语句,以便预处理器找到它已经存在的位置。
Where the preprocessor looks for included files is described here. One solution is to put the xyz.h file in a folder where the preprocessor is going to find it while following that search pattern.
当预处理程序将查找包含的文件中描述了这里。一种解决方案是将 xyz.h 文件放在预处理器将在遵循该搜索模式时找到它的文件夹中。
Alternatively you can change the #include statement so that the preprocessor can find it. You tell us the xyz.cxx file is is in the 'code' folder but you don't tell us where you've put the xyz.h file. Let's say your file structure looks like this...
或者,您可以更改 #include 语句,以便预处理器可以找到它。您告诉我们 xyz.cxx 文件在“代码”文件夹中,但您没有告诉我们您将 xyz.h 文件放在哪里。假设您的文件结构如下所示...
<some folder>\xyz.h
<some folder>\code\xyz.cxx
In that case the #include statement in xyz.cxx should look something like this..
在这种情况下,xyz.cxx 中的 #include 语句应该看起来像这样..
#include "..\xyz.h"
On the other hand let's say your file structure looks like this...
另一方面,假设您的文件结构如下所示......
<some folder>\include\xyz.h
<some folder>\code\xyz.cxx
In that case the #include statement in xyz.cxx should look something like this..
在这种情况下,xyz.cxx 中的 #include 语句应该看起来像这样..
#include "..\include\xyz.h"
Update:On the other other hand as @In silico points out in the comments, if you are using #include <xyz.h>
you should probably change it to #include "xyz.h"
更新:另一方面,正如@In silico 在评论中指出的那样,如果您正在使用,#include <xyz.h>
您可能应该将其更改为#include "xyz.h"
回答by Holger Kretzschmar
Add the "code" folder to the project properties within Visual Studio
将“code”文件夹添加到 Visual Studio 中的项目属性
Project->Properties->Configuration Properties->C/C++->Additional Include Directories
项目->属性->配置属性->C/C++->附加包含目录
回答by sfuqua
I ran into this error in a different situation, posting the resolution for those arriving via search: from within Visual Studio, I had copied a file from one project and pasted into another. Turns out that creates a symbolic link, not an actual copy. Thus the project did not find the file in the current working directory as expected. When I made a physical copy instead, in Windows Explorer, suddenly #include "myfile.h"
worked.
我在另一种情况下遇到了这个错误,发布了通过搜索到达的解决方案:在 Visual Studio 中,我从一个项目复制了一个文件并粘贴到另一个项目中。事实证明,这会创建一个符号链接,而不是实际的副本。因此项目没有按预期在当前工作目录中找到该文件。当我在 Windows 资源管理器中制作物理副本时,突然#include "myfile.h"
起作用了。
回答by Saketh Reddy
The following approach helped me.
以下方法帮助了我。
Steps :
脚步 :
1.Go to the corresponding directory where the header file that is missing is located. (In my case,../include/unicode/coll.h was missing) and copy the directory location where the header file is located.(Copy till the include directory.)
1.进入缺失的头文件所在的对应目录。(在我的情况下,../include/unicode/coll.h 丢失)并复制头文件所在的目录位置。(复制到包含目录。)
2.Right click on your project in the Solution Explorer->Properties->Configuration Properties->VC++ Directories->Include Directories. Paste the copied path here.
2.在解决方案资源管理器中右键单击您的项目->属性->配置属性->VC++目录->包含目录。将复制的路径粘贴到此处。
3.This solved my problem.I hope this helps !
3.这解决了我的问题。我希望这有帮助!