我已经从源代码构建了OpenCV v4.2,并将其安装到/usr/local
。 OPENCVConfig.cmake
文件位于/usr/local/lib/cmake/opencv4
目录中:
paul@paul-desktop:/usr/local/lib/cmake/opencv4$ dir
OpenCVConfig.cmake OpenCVConfig-version.cmake OpenCVModules.cmake OpenCVModules-release.cmake
这是我的CMakeLists.txt
文件,它拼命试图满足find_package
:
cmake_minimum_required(VERSION 3.16.2)
project(af VERSION 0.1.0 LANGUAGES CXX)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_PARALLEL_LEVEL 4)
set(CMAKE_PREFIX_PATH /usr/local/lib/cmake/opencv4)
set(ENV{OPENCV_DIR} /usr/local/lib/cmake/opencv4)
set(OPENCV_DIR /usr/local/lib/cmake/opencv4)
find_package(OPENCV REQUIRED)
add_executable(af main.cpp)
会产生此错误:
[build] CMake Error at CMakeLists.txt:12 (find_package):
[build] By not providing "FindOPENCV.cmake" in CMAKE_MODULE_PATH this project has
[build] asked CMake to find a package configuration file provided by "OPENCV", but
[build] CMake did not find one.
[build]
[build] Could not find a package configuration file provided by "OPENCV" with any
[build] of the following names:
[build]
[build] OPENCVConfig.cmake
[build] opencv-config.cmake
[build]
[build] Add the installation prefix of "OPENCV" to CMAKE_PREFIX_PATH or set
[build] "OPENCV_DIR" to a directory containing one of the above files. If "OPENCV"
[build] provides a separate development package or SDK, be sure it has been
[build] installed.
当我用CMakeCache.txt
打开cmake-gui
并将OPENCV_DIR
手动设置为/usr/local/lib/cmake/opencv4
时,我遇到了同样的错误,OPENCV_DIR
变成了
OPENCV_DIR-NOTFOUND
。
这是怎么回事?在我看来,我已经满足了错误消息中列出的要求,并且在解决类似问题时可以找到任何好的建议。
我不确定这是否重要,但是/usr/share/OpenCV/OpenCVConfig.cmake
属于OpenCV的其他版本。
答案 0 :(得分:1)
包名称区分大小写。在find_package
中使用的OpenCV软件包的专有名称是OpenCV
,而不是OPENCV
。
实际上,CMake中唯一不区分大小写的东西是宏/函数名。 其他所有都是区分大小写的。
某些变量和文件使用名称的大写或小写转换。例如。 OPENCV_DIR
变量在大写中使用包名,而opencv-config.cmake
文件在小写中使用包名。但这并不否认区分大小写的方面。