[英]Visual Studio 2012: 'opencv2/opencv.hpp' : No such file or directory (C1083)
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! 2) 将文件放入 C:\\ 不起作用! (add. directories added) (添加。添加的目录)
3) Empty project with the same include syntax. 3) 具有相同包含语法的空项目。 (add. directories added). (添加。添加的目录)。 WORKS!作品!
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?任何提示可能导致此错误的原因?
打开 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
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 如下图所示
In my case the problem had to do with exported classes.在我的情况下,问题与导出的类有关。
I have 2 VS projects.我有 2 个 VS 项目。 Let's name them A and B. Project A uses classes from project B;让我们将它们命名为 A 和 B。项目 A 使用项目 B 中的类; and project B uses classes of OpenCV.项目 B 使用 OpenCV 类。 Project A didn't use (neither link) OpenCV.项目 A 没有使用(都没有链接)OpenCV。 (as you can imagine project A uses openCV throught project B). (你可以想象项目 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.希望它有用。
In addition to the existing answers.除了现有的答案。 Try to change尝试改变
<opencv2/core.hpp>
to到
"opencv2/core.hpp".
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项目 > 属性 - > 将平台更改为 x64
project property > C/C++ -> General -> Additional include Directories ->{DIR}{PATH}\\opencv\\opencv\\build\\include项目属性 > 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项目属性 > C/C++ -> 所有选项 -> 附加包含目录 ->{DIR}{PATH}\\opencv\\opencv\\build\\include
project property > Linker -> Input -> Additional Dependencies -> Edit.. -> enter 'opencv_world330d.lib' -> OK -> OK项目属性> Linker -> Input -> Additional Dependencies -> Edit.. -> 输入'opencv_world330d.lib' -> OK -> OK
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>
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>
i hope this will help我希望这个能帮上忙
You have to change Project > Properties -> change platform to x64 and the set the bin, lib and include folders again.您必须更改 Project > Properties -> 将平台更改为 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。
If you put the headers within your project.如果你把标题放在你的项目中。 As @CalaveraLoco's answer.正如@CalaveraLoco 的回答。 Could using the relative path to access the header.可以使用相对路径来访问标头。
But it's better to include the project folder path into your project settings.但最好将项目文件夹路径包含在您的项目设置中。
Properties
of the project.打开项目的Properties
。C/C++
选择C/C++
General
选择General
$(ProjectDir);
添加$(ProjectDir);
into Addition Include Directories
Addition Include Directories
On Windows:在 Windows 上:
when you are debug application use 'x64' mode当您调试应用程序时,请使用“x64”模式
This works with VS2015, hope this will help.这适用于 VS2015,希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.