Adding external header to Visual Studio project - visual-studio

I have just created a new, empty, console C++ project in Visual Studio 2012. I create one file called main.cpp, with the following code:
#include "myheader.hpp"
int main()
{
return 0;
}
Then, I right-click on Solution Explorer, choose to add an existing item, and then browse to the location of my file myheader.hpp. Once this is added, I see it appears under Solution Items.
Now, I try to build the project, but I get the error:
Error 1 error C1083: Cannot open include file: 'myheader.hpp': No such file or directory
What's going on?

If the header is not in the project directory, you must use a relative path.
Example:
#include "..\..\SomeOtherDir\myheader.hpp"
Another solution may be to add ..\..\SomeOtherDir to the
C++ / General / Additional Include Directories
properties for the project.

Related

How do I link OpenSceneGraph libraries and includes to Visual Studio properly?

I am trying to compile and build the first basic example from the OSG 3.0 Beginner's Guide (Rui Wang, Xuelei Qian) run on Windows 10 (Build 18363) with Visual Studio Community 19 (16.7.3).
The code looks like this:
#include <osgDBd/ReadFile>
#include <osgViewerd/Viewer> //the "d" is supposed to be there when in Debug solution configuration
int main(int argc, char** argv)
{
osgViewer::Viewer viewer;
viewer.setSceneData(osgDB::readNodeFile("cessna.osg"));
return viewer.run();
}
But the error messages are:
Error (active) E1696 cannot open source file "osgDBd/ReadFile"
Error (active) E1696 cannot open source file "osgViewerd/Viewer"
Error C1083 Cannot open include file: 'osgDBd/ReadFile': No such file or directory
So I rechecked my solution properties, which I had set up following OSG's online documentation "compiling with visual studio" (Linker, C++ properties, ...), as well as my environment variables in Windows OS.
The recommended cmd commands, should something be out of order, didn't help either.
(I deemed it less cluttered leaving out all those screenshots, but I can of course upload them if wished)
I also compared my settings to this answer: How to add additional libraries to Visual Studio project? , which I thought same.
I should add, that I built OSG on a separate drive than Visual Studio or Windows, but I believed setting the environment variables properly should be ok.
Help would be greatly appreciated.
Thank you.
Have you set %OSG_ROOT% ?
I'm not sure what is in the guide, but my typical installation is to set Windows environment variable OSG_ROOT to the main OpenSceneGraph folder in my Program Files (x86), then to add $(OSG_ROOT)\include to my additional include folders and $(OSG_ROOT)\lib to my additional library folders.
Also, it looks like the example you are using has a "d" added to the folder names - should just be osgDB/ReadFile and osgViewer/Viewer for the Release versions - maybe they wanted you to build the debug libraries and add such folders for your includes? I get having a separate lib and bin but I don't know why they would want a separate include folder for Debug vs. Release, so my suggestion would be to remove the d from the include statements, e.g. osgDBd --> osgDB, osgViewerd --> osgViewer, etc.
Unfortunately, the Example applications in the OSG Solution reference the local build folders, not the installed folders, so will not serve as an example of how to reference OSG from its installed location. However, if you are ok building from the local build folder, you could just use the project settings from one of the Examples.

Making local project items accessible from the shared projects in VS C++ 2017

I have deb_sets.h in the main project to set debugging options for the whole project.
Shared projects include this file too. However, it will be different in different main projects.
I get a compilation error fatal error: deb_sets.h: No such file or directory in every shared project file which include this file.
Is my idea possible to achieve?
You need to add the #include "deb_sets.h" in all source files that use this header, but if this header file is in another directory, you need to change "Additional Include Directories" (C++\General section) in the project options to set the header file path.

Visual Studio does not find include files, but paths are correct

For my project, I am using Visual Studio 2015. I have added to my include path the folder $(ProjectDir)Source. In details view of Include Directories, in the list below with Evaluated value, the correct path is listed. When I copy this path using #include "path/file", it finds the file. Or via Start > Run, it opens the path.
In my project I have a .cpp file which includes the file like usual:
#include <file>.
Still, I am receiving the error: Cannot open include file 'file.h' No such file or directory. Error C1083.
I copied an existing solution which had similar includes and adjusted them accordingly. It works now.

MS Visual Studio C1083 for every project

I just encountered problem with Visual Studio 2013, when I get C1083 for every project/solution. Error I am getting looks like this one (path and name differ from project to project)
Error 1 error C1083: Cannot open source file: 'main.cpp': No such file or directory D:\what\c1xx what
there is only one file, main.cpp containing just
#include <stdio.h>
int main(){
printf("hello world");
while (1);
}
so nothing should be wrong there. Project folder contains
Debug
main.cpp
what.sdf
what.sln
what.vcxproj
what.vcxproj.filters
what I find strange, VisualStudio keeps claiming main.cpp does not exist even when I place absolute path to it in vcxproj instead of just filename.
I'd like to note that VisualStudio was working, stopped without me fiddling with anything and reinstalation nor repair did help.
Any help would be much appreciated.

NVIDIA SDK is missing a header file

I am writing a simple program and trying to include this file in my code #include <cutil_inline.h> but I am getting an error..
fatal error C1083: Cannot open include file: 'cutil_inline.h': No such file or directory
I have tried this but still getting the error
Error:
fatal error C1083: Cannot open include file: 'cutil_inline.h': No such file or directory
Solution:
1- right-click on project name in solution explorer window
2- Click "Properties"
3- in left window Click Configuration Properties -> Linker
4- set the value of "Additional Library Directories" to
"$(CUDA_PATH)/lib/$(PlatformName)";"$(NVSDKCOMPUTE_ROOT)/C/common/lib"
5- Right-click on your .cu file
6- Click Properties
7- Click on Cuda Runtime API
8- Set Additional Include Directories to :
$(CUDA_PATH)/include;./;$(NVSDKCOMPUTE_ROOT)/C/common/inc;$(NVSDKCOMPUTE_ROOT)/shared/inc
Can anybody help me out here. ?
Note you are missing a header, not a library. Making changes in Additional Library Directories will not help you.
Find the path cutil_inline.h is in. Make sure your SDK version includes it; if it doesn't, see if your code can do without it. Also note that according to the comment from #talonmies, the cutil package doesn't exist in CUDA 5.
Put the path into Configuration Properties -> C/C++ -> General -> Additional Include Directories.
For me it's under $(NVSDKCUDA_ROOT)\common\inc, but your mileage may vary.

Resources