CMake问题-找不到“ OpenCV”提供的程序包配置文件

时间:2020-10-15 20:17:01

标签: c++ opencv cmake

我在使用Cmake构建项目时遇到了问题,这是我以前从未做过的。我是C ++和Cmake和Makefiles概念的新手。我正在尝试从GitHub上的一些代码重新创建一些结果。如果您想更详细地了解说明/文件,请点击此处:

https://github.com/jan-dufek/Fotokite

所以基本上,他列出了四个步骤:

1-)安装CMake:

https://cmake.org

2-)在终端中,将目录更改为项目的根目录,然后运行以下命令以生成makefile:

cmake。

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下载到了我的桌面上,我尝试将路径合并到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)

首次在此网站上发布,如果不清楚,抱歉,我可以提供更多详细信息!期待您的回复。

2 个答案:

答案 0 :(得分:0)

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

CMakeLists.txt:5(find_package)的CMake错误:不提供 CMAKE_MODULE_PATH中的“ FindOpenCV.cmake”此项目已询问CMake 查找“ OpenCV”提供的软件包配置文件,但CMake 没有找到一个。

找不到“ OpenCV”提供的软件包配置文件 以下任何名称:

OpenCVConfig.cmake

opencv-config.cmake

将“ OpenCV”的安装前缀添加到CMAKE_PREFIX_PATH或进行设置 “ OpenCV_DIR”到包含上述文件之一的目录。如果 “ OpenCV”提供了单独的开发包或SDK,请确保它 已安装。

这意味着当调用find_package时,CMake具有两种查找依赖项的模式,即“模块”模式和“配置”模式。模块模式意味着在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>)

答案 1 :(得分:0)

在使用buildroot进行构建时,我也遇到了类似的问题。

当我检查日志时,发现

>>> xxxxxx Configuring
>>> xxxxxx Installing to target
xxxxxxxxxxxxxx  DESTDIR= xxxxxxxxxxxxxxx

请仔细查看 DESTDIR 变量。可能会受到xxx.mk文件中“ FOO_INSTALL_STAGING = YES ”命令的影响。

相关问题