VSCODE CMAKE不链接软件包

发布于 2025-02-07 22:05:16 字数 1128 浏览 1 评论 0原文

我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趴在窗边数星星i 2025-02-14 22:05:16

似乎include_directories指向意外的内容。

您可以在include_directories在cmakelists.txt中调用添加此内容:

message(
"OpenCV package:
    found: ${OpenCV_FOUND}
    include dir: ${OpenCV_INCLUDE_DIRS}
    libraries: ${OpenCV_LIBS}"
)

查看打印的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:

message(
"OpenCV package:
    found: ${OpenCV_FOUND}
    include dir: ${OpenCV_INCLUDE_DIRS}
    libraries: ${OpenCV_LIBS}"
)

and look at the printed include dir:. The directory it is pointing to, should contain a structure like opencv2\opencv.hpp.

P.S.: I tried your code with the OpenCV – 4.6.0 release with the windows-release package and the build worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文