c++ - CMake问题——找不到 "OpenCV"提供的包配置文件

标签 c++ opencv cmake

我在使用 Cmake 构建项目时遇到问题,这是我以前从未做过的。我是 C++ 以及 Cmake 和 Makefile 概念的新手。我正在尝试从 GitHub 上的一些代码重新创建一些结果。如果您想更详细地查看说明/文件,可以在此处找到:
https://github.com/jan-dufek/Fotokite
所以基本上他列出了四个步骤:
1-)安装CMake:
https://cmake.org
2-)在终端中,将目录更改为项目的根目录并运行以下命令生成makefile:
制作。
3-) 编译项目:
制作
4-) 运行:
./Fotokite

基本上我现在被困在第二步,因为在导航到文件夹并运行“cmake .”后,我的终端中不断出现以下错误。

The C compiler identification is AppleClang 11.0.3.11030032
The CXX compiler identification is AppleClang 11.0.3.11030032
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped     
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.


Could not find a package configuration file provided by "OpenCV" with any
of the following names:

OpenCVConfig.cmake

opencv-config.cmake

Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
我也将 OpenCV 下载到我的 table ​​面上,我尝试将路径合并到 Cmake 文件中,但仍然没有任何运气。
这里也是 Cmakelists.txt:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
project(Fotokite)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
file(GLOB SOURCES
*.h
*.hpp
*.cpp
)
list(FILTER SOURCES EXCLUDE REGEX "main.*.cpp")
list(FILTER SOURCES EXCLUDE REGEX "Visualization.*")
foreach (FILE "" Takeoff GoToWaypoint ExecutePath Land)
add_executable(Fotokite${FILE} ${SOURCES} main${FILE}.cpp)
target_link_libraries(Fotokite${FILE} ${OpenCV_LIBS} pthread)
endforeach(FILE)
第一次在这个网站上发帖,如果有什么不清楚的地方,我很抱歉,如果可以的话,我可以提供更多的细节!期待您的回复。

最佳答案

以下错误消息详细说明了问题的原因:

CMake Error at CMakeLists.txt:5 (find_package): By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "OpenCV", but CMake did not find one.

Could not find a package configuration file provided by "OpenCV" with any of the following names:

OpenCVConfig.cmake

opencv-config.cmake

Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV" provides a separate development package or SDK, be sure it has been installed.


这意味着当调用 find_package制作完成后,CMake 有两种查找依赖项的模式,“Module”模式和“Config”模式。模块模式意味着它可以在 CMakes 模块路径的某个位置找到一个名为 FindOpenCV.cmake 的文件。默认情况下,CMake 附带许多预先准备好的查找模块,但是,默认情况下它不附带用于 OpenCV 的模块。在这种情况下,您可以自己添加它(只需 google 查找 FindOpenCV.cmake,您会找到示例)但是这是错误的方法,我将解释原因。
当您使用 CMake 生成库构建时,如果您希望有依赖于您的库的下游客户端,那么您应该使其易于使用。 CMake 通过“配置”模式支持这一点。当您使用 CMake 编写库作为安装步骤的一部分时(可以运行此步骤以在构建后将库打包到一组可安装的文件和文件夹结构中)。您可以在此处查看如何为项目进行设置的示例:https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file .此时您不需要知道如何执行此操作,只需库应该执行此操作,因为它们具有正确导出库目标的信息。如果他们不这样做,那么用户就必须以“模块”模式访问库,这涉及创建 find<library>.cmake。哪条指令详细说明了如何定位文件。
然而,幸运的是,使用 CMake 的 OpenCV 确实正确地创建和安装了 OpenCVConfig.cmake文件允许用户使用“配置”模式访问它。这里的问题似乎是您尚未将 OpenCV 安装到“配置”模式默认搜索的标准系统安装目录之一。搜索位置列表在此处详细说明:https://cmake.org/cmake/help/v3.19/command/find_package.html .要解决此问题,您可以将 PATH 参数传递给 find_package以便它在其他位置查找:
find_package(OpenCV REQUIRED PATH <location to OpenCV installation>)

关于c++ - CMake问题——找不到 "OpenCV"提供的包配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64379070/

相关文章:

c++ - 如何获得指向编译器选择的重载函数的函数指针?

C++:使用 “().” 和 “()[].”

c++ - 在 Windows 启动时加载应用程序

opencv - 基准标记或相机姿态估计

Python OpenCV LoadDatasetList,最后两个参数是什么?

CMake 使用 NASM 进行链接,但失败了。

c++ - pow(x, 0.5f) 的快速实现是否比快速 sqrt(x) 更快?

opencv读取错误:[h264 @ 0x8f915e0] error while decoding MB 53 20,字节流-7

c++ - 如何编写 CmakeLists.txt 以在 c 中包含 xgboost

cmake - QtCreator CMake 编辑器缩进