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
Visual Studio 2012: 'opencv2/opencv.hpp' : No such file or directory (C1083)
提问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 中打开它?
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
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,我按照以下步骤进行修复:
Project > Properties -> change platform to x64
project property > C/C++ -> General -> Additional include Directories ->{DIR}{PATH}\opencv\opencv\build\include
project property > C/C++ -> All Options -> Additional include Directories ->{DIR}{PATH}\opencv\opencv\build\include
project property > Linker -> Input -> Additional Dependencies -> Edit.. -> enter 'opencv_world330d.lib' -> OK -> OK
项目 > 属性 - > 将平台更改为 x64
项目属性 > C/C++ -> General -> Additional include Directories ->{DIR}{PATH}\opencv\opencv\build\include
项目属性 > C/C++ -> 所有选项 -> 附加包含目录 ->{DIR}{PATH}\opencv\opencv\build\include
项目属性> 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.
但最好将项目文件夹路径包含在您的项目设置中。
- Open
Properties
of the project. - Select
C/C++
- Select
General
- Add
$(ProjectDir);
intoAddition Include Directories
Properties
项目开通。- 选择
C/C++
- 选择
General
- 添加
$(ProjectDir);
到Addition Include Directories