weixin_42725244
2019-12-09 10:59 阅读 1.4k

【已经解决】 Win10环境下采用CMake编译OpenCV项目,提示无法找到opencv

  1. 安装过OpenCV 4.1 win pack版本,同时安装的Intel Sensor SDK第三方软件中有opencv 3.4版本。 都按照操作要求添加了环境变量路径。
  2. 采用CMake编译一个文件出现一直提示错误,这个错误应该是很多人都遇到过的。 CMakeLists.txt文件内容如下:

cmake_minimum_required(VERSION 3.10)

project(CvTrack)
set(CMAKE_BUILD_TYPE Debug)
set(OpenCV_DIR "D:/opencv/build")
find_package(OpenCV REQUIRED)
add_executable(CvTracking "main.cpp")
target_link_libraries(CvTrack ${OpenCV_LIBS})


产生的错误提示:
Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
OpenCV ARCH: x86
OpenCV RUNTIME: vc14
OpenCV STATIC: OFF
CMake Warning at D:/opencv/build/OpenCVConfig.cmake:166 (message):
Found OpenCV Windows Pack but it has no binaries compatible with your
configuration.

You should manually point CMake variable OpenCV_DIR to your build of OpenCV
library.
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
CMake Error at CMakeLists.txt:15 (find_package):
Found package configuration file:
D:/opencv/build/OpenCVConfig.cmake
but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
NOT FOUND.

图片说明

安装目录如下:
图片说明

图片说明

请问,这个问题如何解决呢??

/==/==/==/==/==/==/==/==/==/==/==/==/==/==/==/==/==/==

解决方法:
主要原因:根据提示,OpenCVConfig.cmake文件有问题;实际在OpenCV 4.1 wind pack安装版本中,OpenCVConfig.cmake在其它路径下也有一个文件,修改路径即。
其次原因:设定的工程名为CvTrack,在add_excuatable中的TargetName不对应。所以:重新修正了一下CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(CvTrack)
set(OpenCV_DIR "D:/opencv/build/x64/vc15/lib") # 错误修正
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(CvTrack "main.cpp") # 错误修正
target_link_libraries(CvTrack ${OpenCV_LIBS})

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐