使用vcpkg+cmake+opencv生成项目,却遇到 fatal error: “opencv2/core/core.hpp”: No such file or directory

发布于 2025-01-17 05:39:46 字数 1404 浏览 2 评论 0原文

我使用 VCPKG 下载 OpencV:

./vcpkg install opencv2:x64-windows
Computing installation plan...
The following packages are already installed:
    opencv2[core,eigen,jpeg,png,tiff]:x64-windows -> 2.4.13.7#5
Package opencv2:x64-windows is already installed

Total elapsed time: 2.225 ms

The package opencv2:x64-windows provides CMake targets:

    find_package(OpenCV CONFIG REQUIRED)
    # Note: 15 target(s) were omitted.
    target_link_libraries(main PRIVATE opencv_ml opencv_ts opencv_gpu opencv_ocl)

并像这样编写 cmakelists:

cmake_minimum_required(VERSION 3.10) 

set(CMAKE_TOOLCHAIN_FILE E:/vcpkg/scripts/buildsystems/vcpkg.cmake
  CACHE STRING "Vcpkg toolchain file")

# set the project name 
project(QRCODE)
# add the executable 
add_executable(qrcode main.cpp)

find_package(OpenCV COMPONENTS REQUIRED)
# Additional Include Directories
include_directories( ${OpenCV_INCLUDE_DIRS} )

# Additional Library Directories
link_directories( ${OpenCV_LIB_DIR} )

# Additional Dependencies
target_link_libraries(qrcode ${OpenCV_LIBS})

message("${OpenCV_DIR}")
message("${OpenCV_INCLUDE_DIRS}")

令我困惑的是 cmake 输出如下所示:

E:/vcpkg/installed/x64-windows/share/opencv
/include/opencv;/include

似乎 opencv 没有安装成功,或者 cmake 找不到 opencv 安装路径。 当我使用cmake工具构建项目时,遇到致命错误:“opencv2/core/core.hpp”:没有这样的文件或目录。

I download OpencV using VCPKG:

./vcpkg install opencv2:x64-windows
Computing installation plan...
The following packages are already installed:
    opencv2[core,eigen,jpeg,png,tiff]:x64-windows -> 2.4.13.7#5
Package opencv2:x64-windows is already installed

Total elapsed time: 2.225 ms

The package opencv2:x64-windows provides CMake targets:

    find_package(OpenCV CONFIG REQUIRED)
    # Note: 15 target(s) were omitted.
    target_link_libraries(main PRIVATE opencv_ml opencv_ts opencv_gpu opencv_ocl)

and write cmakelists like this:

cmake_minimum_required(VERSION 3.10) 

set(CMAKE_TOOLCHAIN_FILE E:/vcpkg/scripts/buildsystems/vcpkg.cmake
  CACHE STRING "Vcpkg toolchain file")

# set the project name 
project(QRCODE)
# add the executable 
add_executable(qrcode main.cpp)

find_package(OpenCV COMPONENTS REQUIRED)
# Additional Include Directories
include_directories( ${OpenCV_INCLUDE_DIRS} )

# Additional Library Directories
link_directories( ${OpenCV_LIB_DIR} )

# Additional Dependencies
target_link_libraries(qrcode ${OpenCV_LIBS})

message("${OpenCV_DIR}")
message("${OpenCV_INCLUDE_DIRS}")

and what puzzles me is that cmake output looks like this:

E:/vcpkg/installed/x64-windows/share/opencv
/include/opencv;/include

it seems like opencv was not installed successfully, or cmake couldn't find opencv install path.
When I built the project using cmake tool, encountered with fatal error: “opencv2/core/core.hpp”: No such file or directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文