cmake 找不到“OPENCV”提供的包配置文件
Posted
技术标签:
【中文标题】cmake 找不到“OPENCV”提供的包配置文件【英文标题】:cmake could not find a package configuration file provided by "OPENCV" 【发布时间】:2020-04-02 13:20:37 【问题描述】:我已经从源代码构建了 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(ENVOPENCV_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.
当我用cmake-gui
打开CMakeCache.txt
并手动将OPENCV_DIR
设置为/usr/local/lib/cmake/opencv4
时,我遇到了同样的错误,OPENCV_DIR
变为
OPENCV_DIR-NOTFOUND
.
这里发生了什么?在我看来,我正在满足错误消息中列出的要求以及我可以在类似问题的答案中找到的任何好的建议。
我不确定这是否重要,但 /usr/share/OpenCV/OpenCVConfig.cmake
属于不同版本的 OpenCV。
【问题讨论】:
包名区分大小写。正确找到 OpenCV 是find_package(OpenCV REQUIRED)
我不敢相信它在管道的某个地方被大写了,而且我的文件搜索不区分大小写。如果您发表评论作为答案,我会接受。谢谢。
【参考方案1】:
包名称区分大小写。在find_package
中使用的OpenCV 包的正确名称是OpenCV
,而不是OPENCV
。
实际上,CMake 中唯一不区分大小写的是宏/函数名。 所有内容区分大小写。
一些变量和文件使用大写或小写转换名称。例如。 OPENCV_DIR
变量使用大写 格式的包名,opencv-config.cmake
文件使用小写 格式的包名。但这并不否认区分大小写的方面。
【讨论】:
以上是关于cmake 找不到“OPENCV”提供的包配置文件的主要内容,如果未能解决你的问题,请参考以下文章