Visual Studio 2012: 'opencv2/opencv.hpp' : No such file or directory (C1083)
Asked Answered
T

10

18

This question was asked several times, there are some answers, but this problem is more specific, the additional directories path is set correctly (files are found).

Nevertheless building my project i get the following error:

 fatal error C1083: Cannot open include file: 
 'opencv2/opencv.hpp': No such file or directory

but i can right click on the file and open it in visual studio 2012?

File can be found without a problem

I tried:

1) specifying the full path: WORKS!

#include <D:\frameworks\opencv_2_4\build\include\opencv2\opencv.hpp>

2) Putting the file to C:\ Doesn't Work! (add. directories added)

3) Empty project with the same include syntax. (add. directories added). WORKS!

4) I've configured a VS2010 Version of the same project with CMake, and i have there the same problems.

Any hints what could be causing this error?

Tonsil answered 1/2, 2014 at 16:46 Comment(1)
Use Cmake to generate project files.. That makes sure the include directories and libraries are linked properly.Multiplication
S
14

Open Configuration Properties > C/C+ + > General , and edit the field Additional Include Directories to add these 3 paths (for the headers): C:\OpenCV2.3\build\include\opencv C:\OpenCV2.3\build\include \opencv2 C:\OpenCV2.3\build\include

Subastral answered 23/6, 2014 at 5:29 Comment(0)
D
5

project property => C/C++ => General => Additional include Directories => "put the address of library from your openCV folder eg: C:\opencv\build\include As shown in the picture below enter image description here

Dyslalia answered 13/5, 2014 at 21:28 Comment(0)
T
3

If you put the headers within your project. As @CalaveraLoco's answer. Could using the relative path to access the header.

But it's better to include the project folder path into your project settings.

  1. Open Properties of the project.
  2. Select C/C++
  3. Select General
  4. Add $(ProjectDir); into Addition Include Directories
Templet answered 21/8, 2018 at 6:28 Comment(0)
U
2

In addition to the existing answers. Try to change

<opencv2/core.hpp> 

to

"opencv2/core.hpp". 
Uproar answered 25/1, 2016 at 19:55 Comment(0)
G
1

In my case the problem had to do with exported classes.

I have 2 VS projects. Let's name them A and B. Project A uses classes from project B; and project B uses classes of OpenCV. Project A didn't use (neither link) OpenCV. (as you can imagine project A uses openCV throught project B).

But if any of the exported classes of B (used by A) had a private member of type OpenCV (cv::Mat, for example), in that case, the error C1083 appeared, although i had correctly linked openCV in project B.

My solution was to be carefull with the includes in the *.hpp files of the exported classes of project B.

Hope it's usefull.

Glycerinate answered 2/12, 2015 at 15:26 Comment(0)
L
1

since I am running with 64 bit window 10, visual studio professional 2017, I follows below step to fix:

  1. Project > Properties -> change platform to x64

  2. project property > C/C++ -> General -> Additional include Directories ->{DIR}{PATH}\opencv\opencv\build\include

  3. project property > C/C++ -> All Options -> Additional include Directories ->{DIR}{PATH}\opencv\opencv\build\include

  4. project property > Linker -> Input -> Additional Dependencies -> Edit.. -> enter 'opencv_world330d.lib' -> OK -> OK

Lining answered 24/4, 2018 at 4:34 Comment(1)
I don't have #4. Only one without the final "d"Wolfgang
S
1

On Windows:

  1. In Search, search for and then select: “System” (Control Panel). Click on the “Advanced System Settings” link.
  2. Click Environment Variables. In System Variables, click on “Path”.
  3. Click on “Modify”. Click on “New” and add the following (without quotation marks): “C:\opencv\build\x64\vc14\lib\”.
  4. Click on “New” again and add the following (without quotation marks): “C:\opencv\build\x64\vc14\bin\”.
  5. Restart Windows.
  6. Open Visual Studio and create a new project. On “Solution Explorer”:
  7. Right click on the project title and then go to “Properties”. Change Platform to “x64”.
  8. Go to “C/C++” -> “General” -> “Additional Include Directories” and add (without quotation marks) “C:\opencv\build\include”. Click on “Apply”.
  9. Go to “Linker” -> “General” -> “Additional Library Directories” and add (without quotation marks) “C:\opencv\build\x64\vc14\lib”. Click on “Apply”.
  10. Go to “Linker” -> “Input” -> “Additional Dependencies” and add (without quotation marks) “opencv_world310.lib;opencv_world310d.lib;”. Click on “Apply”.

when you are debug application use 'x64' mode

This works with VS2015, hope this will help.

Swound answered 18/6, 2020 at 14:7 Comment(1)
# 10, the file finishing with d does not existWolfgang
S
0

that's funny but it seems that Visual Studio can't find the rigt headers files simply because there is not Opencv2 folder in the Opencv2 folder i mean that when reading the source code

#include <opencv2/core/core.hpp>

and following the include directories location,thus

$(OPENCV_DIR)\build\include\opencv2

he will try to find some

$(OPENCV_DIR)\build\include\opencv2\opencv2\core\core.hpp

which he will never find simply because the base directory is mismatch

to solve this problem just delete the base directory(opencv2) from the include directive :

#include <core.hpp>

i hope this will help

Shawnee answered 7/8, 2016 at 21:46 Comment(0)
R
0

You have to change Project > Properties -> change platform to x64 and the set the bin, lib and include folders again.

After this You have to also change "Solution platforms" tab from x86 to x64.

After this, you will be able to use OpenCV.

Ritual answered 7/11, 2017 at 21:6 Comment(1)
No, I am not able toWolfgang
K
0

I had same problem in Qt. There was a space in my path ( "D:\Program files\OpenCv_Build") and didn't know this can lead to an error. I reinstalled the OpenCv in a new path without space ("D:\OpenCv_Build"), and this error didn't occoured!

The answer in my case is escaping spaces in a Qt ".pro" file as below:

//Escape spaces and backslashes using the $$quote function

PATH_WITH_SPACES = $$quote(D:/program\ files/OpenCv_Build/)

//Set the path in your project variables or configurations

INCLUDEPATH += $$PATH_WITH_SPACES

Kulseth answered 5/11, 2023 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.