C++ Visual Studio 2012:“opencv2/opencv.hpp”:没有这样的文件或目录 (C1083)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21500725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:40:42  来源:igfitidea点击:

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

c++opencvvisual-studio-2012build

提问by user1767754

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?

但我可以右键单击该文件并在 Visual Studio 2012 中打开它?

File can be found without a problem

可以毫无问题地找到文件

I tried:

我试过:

1) specifying the full path: WORKS!

1)指定完整路径:WORKS!

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

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

2) 将文件放入 C:\ 不起作用!(添加。添加的目录)

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

3) 具有相同包含语法的空项目。(添加。添加的目录)。作品!

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

4) 我用 CMake 配置了同一个项目的 VS2010 版本,我也遇到了同样的问题。

Any hints what could be causing this error?

任何提示可能导致此错误的原因?

回答by Tom J Muthirenthi

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

打开 Configuration Properties > C/C++ > General ,并编辑字段 Additional Include Directories 以添加以下 3 个路径(用于标题): C:\OpenCV2.3\build\include\opencv C:\OpenCV2.3\build\包括 \opencv2 C:\OpenCV2.3\build\include

回答by hab

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

project property => C/C++ => General => Additional include Directories => "把你的openCV文件夹中的库地址例如:C:\opencv\build\include 如下图所示 在此处输入图片说明

回答by S. Huerta

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).

我有 2 个 VS 项目。让我们将它们命名为 A 和 B。项目 A 使用项目 B 中的类;项目 B 使用 OpenCV 类。项目 A 没有使用(都没有链接)OpenCV。(你可以想象项目 A 通过项目 B 使用 openCV)。

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.

但是如果 B 的任何导出类(由 A 使用)有一个 OpenCV 类型的私有成员(例如 cv::Mat),在这种情况下,错误 C1083 就会出现,尽管我在项目 B 中正确链接了 openCV。

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

我的解决方案是小心包含在项目 B 的导出类的 *.hpp 文件中。

Hope it's usefull.

希望它有用。

回答by CalaveraLoco

In addition to the existing answers. Try to change

除了现有的答案。尝试改变

<opencv2/core.hpp> 

to

"opencv2/core.hpp". 

回答by jihed gasmi

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

这很有趣,但似乎 Visual Studio 找不到 rigt 头文件仅仅是因为 Opencv2 文件夹中没有 Opencv2 文件夹我的意思是在阅读源代码时

#include <opencv2/core/core.hpp>

#include <opencv2/core/core.hpp>

and following the include directories location,thus

并遵循包含目录位置,因此

$(OPENCV_DIR)\build\include\opencv2

$(OPENCV_DIR)\build\include\opencv2

he will try to find some

他会尝试找到一些

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

$(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 :

要解决这个问题,只需从包含指令中删除基本目录(opencv2):

#include <core.hpp>

#include <core.hpp>

i hope this will help

我希望这个能帮上忙

回答by jok23

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

您必须更改 Project > Properties -> change platform to x64 并再次设置 bin、lib 和 include 文件夹。

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

在此之后,您还必须将“解决方案平台”选项卡从 x86 更改为 x64。

After this, you will be able to use OpenCV.

在此之后,您将能够使用 OpenCV。

回答by mya

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

由于我运行的是 64 位窗口 10,visual studio Professional 2017,我按照以下步骤进行修复:

  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

  1. 项目 > 属性 - > 将平台更改为 x64

  2. 项目属性 > C/C++ -> General -> Additional include Directories ->{DIR}{PATH}\opencv\opencv\build\include

  3. 项目属性 > C/C++ -> 所有选项 -> 附加包含目录 ->{DIR}{PATH}\opencv\opencv\build\include

  4. 项目属性> Linker -> Input -> Additional Dependencies -> Edit.. -> 输入'opencv_world330d.lib' -> OK -> OK

回答by JustWe

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

如果你把标题放在你的项目中。正如@CalaveraLoco 的回答。可以使用相对路径来访问标头。

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

但最好将项目文件夹路径包含在您的项目设置中。

  1. Open Propertiesof the project.
  2. Select C/C++
  3. Select General
  4. Add $(ProjectDir);into Addition Include Directories
  1. Properties项目开通。
  2. 选择 C/C++
  3. 选择 General
  4. 添加$(ProjectDir);Addition Include Directories