0

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

第一次在这个网站上发帖,如果有什么不清楚的地方,我很抱歉,如果可以的话,我可以提供更多的细节!期待您的回复。

4

2 回答 2

0

我在使用 buildroot 构建某些东西时看到了类似的问题。

当我检查日志时,发现

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

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

于 2020-10-23T14:37:48.183 回答
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-文件. 此时您不需要知道如何执行此操作,只需库应该执行此操作,因为它们具有正确导出库目标的信息。如果他们不这样做,那么用户就必须以“模块”模式访问库,这涉及创建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>)
于 2020-10-17T08:08:08.803 回答