Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fatal error C1083: Cannot open include file: 'xyz.h': No such file or directory?

Tags:

c++

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.

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.

like image 341
Apoorva sahay Avatar asked Oct 17 '11 06:10

Apoorva sahay


3 Answers

Add the "code" folder to the project properties within Visual Studio

Project->Properties->Configuration Properties->C/C++->Additional Include Directories

like image 109
codencandy Avatar answered Sep 22 '22 12:09

codencandy


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.

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.

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

<some folder>\xyz.h
<some folder>\code\xyz.cxx

In that case the #include statement in xyz.cxx should look something like this..

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

#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"

like image 42
Frank Boyne Avatar answered Sep 25 '22 12:09

Frank Boyne


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.

like image 30
sfuqua Avatar answered Sep 24 '22 12:09

sfuqua