简体   繁体   English

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

[英]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,我按照以下步骤进行修复:

  1. Project > Properties -> change platform to x64项目 > 属性 - > 将平台更改为 x64

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

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

  4. 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.但最好将项目文件夹路径包含在您的项目设置中。

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

On Windows:在 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\\”.单击“新建”并添加以下内容(不带引号):“C:\\opencv\\build\\x64\\vc14\\lib\\”。
  4. Click on “New” again and add the following (without quotation marks): “C:\\opencv\\build\\x64\\vc14\\bin\\”.再次单击“新建”并添加以下内容(不带引号):“C:\\opencv\\build\\x64\\vc14\\bin\\”。
  5. Restart Windows.重新启动 Windows。
  6. Open Visual Studio and create a new project.打开 Visual Studio 并创建一个新项目。 On “Solution Explorer”:在“解决方案资源管理器”上:
  7. Right click on the project title and then go to “Properties”.右键单击项目标题,然后转到“属性”。 Change Platform to “x64” .将平台更改为“x64”
  8. Go to “C/C++” -> “General” -> “Additional Include Directories” and add (without quotation marks) “C:\\opencv\\build\\include”.转到“C/C++”->“常规”->“附加包含目录”并添加(不带引号)“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”.转到“链接器”->“常规”->“附加库目录”并添加(不带引号)“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;”.转到“链接器”->“输入”->“附加依赖项”并添加(不带引号)“opencv_world310.lib;opencv_world310d.lib;”。 Click on “Apply”.点击“应用”。

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.

相关问题 错误C1083无法在VS 2015中打开包含文件:&#39;opencv2 \\ opencv.hpp&#39; - Error C1083 Cannot open include file: 'opencv2\opencv.hpp' in VS 2015 致命错误 C1083:无法打开包含文件:&#39;opencv2/core.hpp&#39;:没有那个文件或目录 - Fatal error C1083: Cannot open include file: 'opencv2/core.hpp': No such file or directory 致命错误:opencv2/opencv.hpp:没有这样的文件或目录#include“opencv2/opencv.hpp” - fatal error: opencv2/opencv.hpp: No such file or directory #include "opencv2/opencv.hpp" VS2019:致命错误 C1083 无法打开头文件:&#39;opencv.hpp&#39; - VS2019:fatal error C1083 Cannot open header file: 'opencv.hpp' opencv2 / opencv.hpp:使用Eclipse IDE时没有这样的文件或目录 - opencv2/opencv.hpp: No such file or directory using Eclipse IDE <opencv2/opencv.hpp> ,<opencv2/imgproc.hpp> ,<opencv2/highgui.hpp> 无此文件或目录 - <opencv2/opencv.hpp>, <opencv2/imgproc.hpp>, <opencv2/highgui.hpp> no such file or directory 无法在 Visual Studio 2019 中打开源文件 opencv2/opencv.hpp - cannot open source file opencv2/opencv.hpp in visual studio 2019 介子和 OpenCV: fatal error: opencv2/opencv.hpp: No such file or directory - Meson and OpenCV: fatal error: opencv2/opencv.hpp: No such file or directory 通过 vcpkg 安装 package 导致“opencv2/opencv.hpp:没有这样的文件或目录”错误 - Installing package via vcpkg causing a "opencv2/opencv.hpp: No such file or directory" error 致命错误:opencv2/core.hpp:没有这样的文件或目录 Ubuntu 和 Visual Studio 代码 - fatal error: opencv2/core.hpp: No such file or directory Ubuntu and Visual Studio Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM