VSCODE CMAKE不链接软件包
我正在尝试在VS代码中使用OPENCV创建一个项目,尽管CMAKE没有发生任何问题,但仍未检测到包含的标头。我的cmake代码如下:
cmake_minimum_required(VERSION 3.0.0)
project(ASCII VERSION 0.1.0)
include(CTest)
enable_testing()
find_package( OpenCV REQUIRED PATHS "C:/opencv")
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable( ASCII main.cpp )
target_link_libraries( ASCII ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
我的main.cpp文件如下:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
Mat image;
image = imread("C:/Users/Vivek/lenna.png");
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
我一直遇到错误:
main.cpp(2): fatal error C1083: Cannot open include file: 'opencv2/opencv.hpp': No such file or directory
这是我第一次使用CMAKE,因此我不完全确定问题是什么。只有当我尝试运行main时,它不会对Cmake本身丢弃任何错误。
I'm trying to create a project using OpenCV in VS Code and I'm having an issue where the included header is not being detected despite no issues occurring with CMake. My CMake code is as follows:
cmake_minimum_required(VERSION 3.0.0)
project(ASCII VERSION 0.1.0)
include(CTest)
enable_testing()
find_package( OpenCV REQUIRED PATHS "C:/opencv")
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable( ASCII main.cpp )
target_link_libraries( ASCII ${OpenCV_LIBS} )
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
My main.cpp file is as follows:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
Mat image;
image = imread("C:/Users/Vivek/lenna.png");
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
I keep getting the error:
main.cpp(2): fatal error C1083: Cannot open include file: 'opencv2/opencv.hpp': No such file or directory
This is my first time working with CMake, so I'm not entirely sure what the issue is. It doesn't throw any errors with CMake itself, only when I try to run main.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎
include_directories
指向意外的内容。您可以在
include_directories
在cmakelists.txt中调用添加此内容:查看打印的
include dir dir:
。它指向的目录应包含一个结构,例如opencv2 \ opencv.hpp
。PS:我使用
OpenCV –4.6.0
使用Windows-Release软件包发布了您的代码,并且构建工作。It seems like, that the
include_directories
is pointing to unexpected content.You could add this after the
include_directories
call in the CMakeLists.txt:and look at the printed
include dir:
. The directory it is pointing to, should contain a structure likeopencv2\opencv.hpp
.P.S.: I tried your code with the
OpenCV – 4.6.0
release with the windows-release package and the build worked.