C++ project is not finding its header files (visual studio) - c++

I have not used C++ in visual studio in a lonnng lonnng time so probably this is a basic question but I would like some help.
I am opening someone else C++ code and the first thing I notice is that it is not recognizing its includes.
For example I have a main.cpp that has
#include "stdafx.h"
#include "myheader.h"
this cpp file is inside a "source" folder and those header files are under a "headers" folder.
I got an error "cannot open source file "stdafx.h" and "cannot open source file "myheader.h"
It is been ages I haven't touched C++ in visual studio. What configuration I should do to fix this?

if source and headers folders are in same level in folder structure you can use
#include "..\headers\myheader.h"
Similarly locate your stdafx.h and add the relative path to the .cpp file.

Related

Visual studio code rename header

Anyone know how to rename a header file in vscode so that all includes of the header file will be updated accordingly?
For example, if I rename Header0.h to Header1.h, all includes will change from
#include "Header0.h"
to
#include "Header1.h"
Use of extensions is also welcome

OpenCV Include error "Cannot open source file"

I am new in OpenCV. I had install Visual Studio 2015 and OpenCV3.1.
I had included all the dependencieas and include file location.
But I am getting error:
cannot open source file"opencv2/imgproc/imgproc.hpp"
cannot open source file"opencv2/imgcodecs.hpp"
cannot open source file"opencv2/highgui/highgui.hpp"
Anyone can help whats is the problem?
In the additional Include directories the path should be something like .. 'C:\OpenCV-3.0.0\opencv\build\include' once whether it is
#include "opencv2/imgcodecs.hpp" or #include "opencv2/imgcodecs/imgcodecs.hpp" because in the version i am using header file inside the folder imgcodecs.

How to include header files (.h) created in a project from source files (.cpp) in Visual 2010?

I have created a header file in a project. In the same project I have a source (.cpp) file.
I have no idea how to declare/include that header file in my source file.
I'm using Visual 2010.
Add the following line at the top of the .cpp file:
#include "yourheaderfile.h"
At the top of you .CPP file write
#include "header.h"
Make sure the appropriate vc++, c++, and linker options are set in the project settings. Default settings are usually enough for a from-scratch project

Trying to build existing project, lots of "Cannot open include file: 'StdAfx.h': No such file or directory"

I've been handed the source code for a very large c++ project and asked to make a small change to support some new hardware. I'm not very familiar with c++, as I mostly use C# these days.
When I built the project I'm getting 20+
Error 2 error C1083: Cannot open include file: 'StdAfx.h': No such file or directory D:.. thefile.cpp
From my understanding the "StdAfx.h" is to do with precompiled headers, and is automatically generated?
I followed the answer on this question:
1 Ensure you have the file "stdafx.h" in your project. If you don't
(e.g. you removed it) just create a new temporary project and copy the
default one from there;
but in doing so noticed that the created stdafx.h file doesn't have the capitalisation of the referenced "StdAfx.h"
I managed to get rid of a single error by copying in the generated file from a new project and changing:
#include "StdAfx.h"
to:
#include "stdafx.h"
I can't help but think this project was using StdAfx.h (there are about 150 references to it) for a reason, and that I shouldn't be adding a bunch of stdafx.h and stdafx.cpp files scattered around the place.
Is there some way of referencing a global stdafx.h file that was being used that could be causing this error?
In Windows, file names are not case-sensitive.
You can't expect that someone else stdafx.h file will be useful in your project. You need to find the original one.
Typically, one project uses one header file for precompiled header, shared by every source file that includes it.

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

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.
Add the "code" folder to the project properties within Visual Studio
Project->Properties->Configuration Properties->C/C++->Additional Include Directories
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"
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.
This problem can be easily solved by installing the following Individual components:
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.)
2.Right click on your project in the Solution Explorer->Properties->Configuration Properties->VC++ Directories->Include Directories.
Paste the copied path here.
3.This solved my problem.I hope this helps !