Reputation: 411
In C++ with Visual studio 2017,
I copied some header files into my project folder, then added them under the "solution explorer" in c++. Now when I write
#include "name.h"
it prints an error under include, and says "cannot open source file".
Why, and what can I potentially do to fix it?
I only just downloaded VS and am learning c++ for the first time.
Upvotes: 18
Views: 348018
Reputation: 299
please aware that the Properties page is depend on Configuration build. You may need to check that select correct Configuration build in Project Property page.
Upvotes: 0
Reputation: 1
if none of above answers does not solve your problem I would suggest changing your included header to one that match your case as example instead of using (for windows):
#include <unistd.h> //read() , write() , sleep()..
you can use:
#include <io.h> // _read() , _write()
#include <windows.h> //sleep()
make sure that your system support included headers
I wish it solved future problems.
Upvotes: 0
Reputation: 1
In Visual Studio, Right click on project and in Configuration Properties find C/C++ and then General/ In The window at the right side pick up a directory at Additional Include Directories row.
All these steps described above to resolve problem of finding header file work if you perform them both for 64-bit and for 32-bit platform. Or you can choose all Platforms item in the Configuration settings above
Upvotes: 0
Reputation: 1
Go to project properties and set configuration and platform to ALL and then under C/C++ -> General -> Additional Include Directories add $(SolutionDir)(use this if your solution is stored where your project is stored if not then navigate wherever you have stored your projects header files and hit enter.
Upvotes: 0
Reputation: 1
Note: This answer is good if you use Microsoft Visual Studio IDE.
This error usually occurs when the compiler cannot find the header file.
You can try the following steps:
Upvotes: 0
Reputation: 87
Edit: This question was just recently updated, this answer is no longer relevant.
For anyone here that still hasn't found a way to fix this, try to modify/redownload Python with the boxes for Download debugging symbols and Download debug binaries Checked.
Read more at a mslearn article and this helpful tutorial site called DelftStack.
Upvotes: 0
Reputation: 79
For anyone still scratching their heads, you're not "supposed to" #include your own headerfiles with triangle quotes (<>), You're supposed to use "Quotation marks". It is a common mistake.
Upvotes: 2
Reputation: 271
There is more information here on how to deal with this problem: Where does Visual Studio look for C++ header files?
For me, I followed xflowXen's answer and then at "Include Directories" typed in the specific pathname where my header file was located followed by a semicolon, something like: C:\Users\name\source\repos\p2-A\p2-A; then applied the changes and the issue went away.
Upvotes: 4
Reputation: 446
If you're using Visual studio, right click on the project and then on Properties, Under Configuration Properties click on C\C++ and then add the directory to your header files under the Additional Include Directories section.
Upvotes: 24
Reputation: 28872
Visual Studio (or rather the compiler) needs to know where to look for the included file. Check out your include path in your VS project.
Upvotes: 0