I have VS2013 community edition, I just installed OpenCV in a directory c:\openCV3 and there is a build subfolder with an include subfolder of that etc, everything looks normal. So I create an empty project with the line#include <opencv2/opencv.hpp> but I get
Error 1 error C1083: Cannot open include file: 'opencv2/opencv.hpp': No such file or directory d:\devt\cplusplus\opencv\test1\test1\source.cpp 1 1 Test1
However I have modified my project's additional include directories to this:
C:\OpenCV3\build\include\opencv;C:\OpenCV3\build\include\opencv2;C:\OpenCV3\build\include;%(AdditionalIncludeDirectories)
But nothing doing, the mistake does not go away. Pretty much the same question has been asked before but the answers do not work for me.
Update:
I right clicked on <opencv2/opencv.hpp> and, in the popup menu chose OpenDocument.
I got the following message box:
What I found surprising is that there is no mention of my set of additional include directories.
Instead of use the includes C:\OpenCV3\build\include\opencv and C:\OpenCV3\build\include\opencv2, try to use C:\OpenCV3\build\include\. When you call an include you're already telling the folder you are using:
#include <opencv2/opencv.hpp>
In that case, VS is searching opencv2/opencv.hpp in folder opencv2... VS must search in the folder include, so it will found opencv2/opencv.hpp...
(or you can try to modify your include to "#include "
Hope it helps.
I faced similar issues with VS2013 - it felt that Additional Include Directories was not working.
However, as I figured out later, when editing
Project -> Properties -> C/C++ -> General -> Additional Include Directories
I didn't pay attention on the selected Configuration: on the top right corner of the properties panel (Debug/Release etc.).
You can choose All Configurations so that your changes apply to both Release and Debug building modes, or you should setup proper individual configurations (set Additional Include Directories etc.) per build type.
Related
I previously had all of my source files in the same folder just scattered about, but I was getting tired of the disorder, so I created a folder hierarchy and organized my headers and .cpp files in those folders, and changed the ClInclude tags in the projects .vcxproj file accordingly. I then changed all the #include rows in the source headers to match the new location of the headers.
Now when I compile I get a heap of errors saying that the namespace "math" can't be found. The namespace could be found before the file organizing, so the problem should be something with that, but that #includes works fine.
If I write
using namespace
the autocomplete finds the namespace just fine, and no red wiggly lines show up in the text interface.
I'm using VS17 Community.
There are actually two ways to resolve your issue. You've already noted the first, that you can always use relative paths (relative to the source file).
#include "..\Math\math.h"
This will work just fine. You can also modify your C++ Project Properties to add a list of include directories. This will be very useful for you when you begin working on projects that use a lot of libraries To add include directories you need to:
right-click on your project in the solution explorer and select Properties.
In the left pane, click on the C/C++ > General tab.
On the property that says Additional Include Directories, click the drop down arrow (you may need to click inside the text first) and select Edit...
From here, you can add a list of include directories that you will be using with your project. You can use:
Absolute Paths
C:\Path\to\Math
Relative Paths (relative to your .vcxproj file)
..\..\relative\path\to\Math
Macros (Visual Studio will list your available macros)
($SolutionDir)..\path\to\Math
You'll see the use of the macros a lot when it comes to C++ and other Visual Studio projects not just for include directories, but for build events as well.
Once you've added a list of include directories, you can go back to including your headers in the source code as normal:
#include "math.h"
In the event you need to use a relative path from one of your included folders, you can do that as well.
// some directory inside of Math
#include "MoreMath\moremath.h"
// some directory above Math
#include "..\AboveMath\abovemath.h"
Hope this helps!
I solved it...
Remove this question if necessary. The problem was that I didn't backtrack the filepath in my #include "math.h". They should instead have said #include "..\Math\math.h".
I was trying to re-use an available source code for my own project, it can be found here:
https://github.com/TadasBaltrusaitis/OpenFace
I tried compiling project FeatureExtraction of the original code, everything was fine. Then I created a new empty project and added the following #include:
#include "LandmarkCoreIncludes.h"
#include <Face_utils.h>
#include <FaceAnalyser.h>
#include <GazeEstimation.h>
These are exactly the same as in project FeatureExtraction in the provided source code. I've already changed the additional include directories in C/C++ general tab into:
$(SolutionDir)\lib\local\FaceAnalyser\include
$(SolutionDir)\lib\local\LandmarkDetector\include
However, it still gave me "cannot open source file error".
Update: If I put the absolute path of the header file directly to the code it is OK, however if I put the absolute path to the Additional Include Directories, the error remained.
Use #include "header.h" instead of the one with diamonds (< and >) which looks in another directory.
After that, check if the header files really are in these directories. If they are, you should check the $(SolutionDir) ( I don't use a '\' after the $(SolutionDir) but it may work out as well).
Try to locate and delete the .suo file and restart VS
Looks like I had same "bug" as mentioned in this post here:
Visual Studio does not honor include directories
After having changed the Additional Include Directories for all platforms instead, the code was compiled without any errors.
I have been seeing this occasionally, but this project in particular is causing me to tear my hair out.
I have my .cpp.
#include <nppi.h>
#include <cuda.h>
#include <device_functions.h>
#include <cuda_runtime.h>
The Headers are in My project directory, in:
<Project file>\Thirdparty\CUDA\v8.0\include
my Additional includes are:
$(ProjectDir)Thirdparty\CUDA\v8.0\include
i have also tried:
Thirdparty\CUDA\v8.0\include
The includes are not found by intellisense, and i cannot open them with a right click. What am i doing wrong? or is this a bug?
Even with a hardcoded path in the Additional includes, the files are not found.
I am in Release mode. If i switch to Debug mode, some of the files are found, but some are not. The Additional includes seem to stay the same when I switch, this seems odd. (I have not added additional includes for Debug).
Thank you for your help, this is driving me mad.
Create a new folder named "include" in your project directory.
Right-click on the project and then on Properties.
CUDA C/C++ -> Additional Include Directories. Type into the upper half $(ProjectDir)include. it should evaluate this path correctly. Check that!
In your kernel.cu that includes your main-function, type in #include "include\mycode.cu". That worked for me. Good luck!
I'm getting the following error :
"fatal error C1083: Cannot open include file"
for one of my header files being #included in stdafx.h. I have set the include and library paths in the project dependencies, Tried to include them in additional include section. On top of that when I right click the
#include <BCGCBProInc.h>
it is able to open the file and show it to me. So it can find and open the file but instead gives me the error. I am using VS2012 on Windows 7 and the header is in a different location then the project.
What am I doing wrong / not doing right?
1.
#include <BCGCBProInc.h>
is not the same as
2.
#include "BCGCBProInc.h"
Different search pathes apply to both variants of including a file.
The pathes looked up when using variant 1. are those defined as default search pathes like
/usr/include for IXish systems
$(VCInstallDir)include also called VC++ Directories for VC
The pathes used when using 2. are those added via the option -I (/I for VC).
In Visual Studio, right-click your project and choose Properties. Select the VC++ Directories option in the left pane, and then look at the Include Directories and Library Directories in the right pane. Make sure they are using relative paths and not absolute paths. If they must be absolute paths, then every machine you run this project on will have to have the exact same path. Absolute paths look like this:
D:/Development/MyProject/includes
Relative paths can be done using $(ProjectDir) to make it relative to the project, or $(SolutionDir) to make it relative to the solution (if different from project), and would look something like this:
$(ProjectDir)../includes
or
$(SolutionDir)includes
What I had to do to get it to compile was change
#include "BCGCBProInc.h"
to this
#include "C:\Program Files (x86)\BCGSoft\BCGControlBar Professional Evaluation\BCGCBPro\BCGCBProInc.h"
I'm not sure why because I included the path in the VC++ Directories. When I browse for the path it changes (x86) to %29x86%29 which is what I thoght was screwing it up but that is not the case because I manually changed it back to (x86).
My plan is when I eventually get what i need to get done, I will bring the libs and includes into the project locally and make the paths relative
I have recently gone from Code::Blocks to Visual Studio, and in Code::Blocks one could just add a class and then include it straight away. However, whenever I do the same in Visual Studio with the following statement:
#include "includedFile.h"
or
#include "include/includedFile.h"
It doesn't work and instead I get the error:
cannot open include file: 'includedFile.h'; no such file or directory.
Is there some box or setting that I have to tick? Or do I have to add each header as a dependency manually?
Here is the code for the class in question:
Public.h:
#pragma once
class Public
{
public:
static const int SCREEN_WIDTH=1000;
static const int SCREEN_HEIGHT=1250;
Public(void);
~Public(void);
};
Public.cpp:
#include "Public.h"
Public::Public(void)
{
}
Public::~Public(void)
{
}
How it is being included:
#include "Public.h"
I had this same issue going from e.g gcc to visual studio for C programming. Make sure your include file is actually in the directory -- not just shown in the VS project tree. For me in other languages copying into a folder in the project tree would indeed move the file in. With Visual Studio 2010, pasting into "Header Files" was NOT putting the .h file there.
Please check your actual directory for the presence of the include file. Putting it into the "header files" folder in project/solution explorer was not enough.
Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.
And be sure that your Configuration and Platform are the active ones. Example: Configuration: Active(Debug) Platform: Active(Win32).
You need to set the path for the preprocessor to search for these include files, if they are not in the project folder.
You can set the path in VC++ Directories, or in Additional Include Directories. Both are found in project settings.
By default, Visual Studio searches for headers in the folder where your project is ($ProjectDir) and in the default standard libraries directories. If you need to include something that is not placed in your project directory, you need to add the path to the folder to include:
Go to your Project properties (Project -> Properties -> Configuration Properties -> C/C++ -> General) and in the field Additional Include Directories add the path to your .h file.
You can, also, as suggested by Chris Olen, add the path to VC++ Directories field.
I found this post because I was having the same error in Microsoft Visual C++. (Though it seems it's cause was a little different, than the above posted question.)
I had placed the file, I was trying to include, in the same directory, but it still could not be found.
My include looked like this: #include <ftdi.h>
But When I changed it to this: #include "ftdi.h" then it found it.
If your problem is still there it's certainly because you are trying to compile a different version from your current settings.
For example if you set your Additional Include Directories in Debug x64, be sure that you are compiling with the same configuration.
Check this: Build > Configuration Manager... > There is problably something like this in your active solution configuration: Debug x86 (Win32) platform.
For me, it helped to link the projects current directory as such:
In the properties -> C++ -> General window, instead of linking the path to the file in "additional include directories". Put "." and uncheck "inheret from parent or project defaults".
Hope this helps.
I tried the other answers here as well, but my problem had nothing to do with the include paths or files missing incorrect #includes. I had two configurations, each set to the exact same include directories. One configuration could resolve the includes, the other could not.
After selecting my project and going to Project -> Properties, I selected both configurations through the Configuration dropdown -> Multiple Configurations... option. Comparing the two I found that C/C++ -> Language -> Conformance Mode was different. The "incorrect" configuration had a value of Default for some reason, and switching it to Yes or No allowed the paths to be resolved.
TL;DR: If you have one configuration with the same include directories but the other isn't finding the files, I suggest to try comparing the configurations.
If you've tried the other answers and your include file still can't be found, here are some additional debugging steps and sanity-checks:
Ensure that you are building to a platform that is supported by your code. (If not, consider removing this platform as a target)
Verify that the filename/path is correct. Modify your source code to #include the whole absolute path of the header file instead, and see if the file can be found now. If not, copy-paste the path from your source code into a command line to validate that the file exists at that full path with no typos. Open the header file to ensure you have read access. (Change the source code back when done.)
If you've already added the path to Additional Include Directories, try clicking the drop-down combo box for Additional Include Directories, and select <Edit...>. This will show you evaluated values of paths. (If it does not show the correct evaluated values, variables in your path might not be set. Click Macros>> to see variables.) Copy-paste the evaluated path into windows explorer to validate that the path exists.
Create a new empty C++ "Windows Console Application" project. Set just the one Include Directory, and #include just the one file in your main.cpp, and see if that builds.