gpt4 book ai didi

c++ - 开罗图书馆和 Cmake

转载 作者:太空狗 更新时间:2023-10-29 21:14:08 26 4
gpt4 key购买 nike

我是 C++ 和 cmake 的新手。我按照写的方式安装了 cairo 库 here通过端口。现在我想将 cairo 包含到我的项目中。我编写了 CmakeLists.txt 命令,如图所示 here .

cmake_minimum_required(VERSION 3.6)
project(HelloOpenGL)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(HelloOpenGL ${SOURCE_FILES})

#find_package(ImageMagick COMPONENTS Magick++)
#include_directories(${ImageMagick_INCLUDE_DIRS})
#target_link_libraries(HelloOpenGL ${ImageMagick_LIBRARIES})

find_package(Cairo)
include_directories(${Cairo_INCLUDE_DIRS})
target_link_libraries(HelloOpenGL ${Cairo_LIBRARIES})

if(CAIRO_FOUND)
message("Cairo found")
else()
message("Cairo not found")
endif()

但它不起作用,我得到了这个输出 -

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

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

CairoConfig.cmake
cairo-config.cmake

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

请帮助我正确地包含 cairo

最佳答案

问题是您的 CMake 版本没有(顺便说一下,即使是最新的 CMake 开发版本也没有 ... https://gitlab.kitware.com/cmake/cmake/tree/master/Modules )运行命令 find_package(Cairo) 所需的文件 FindCairo.cmake 并且您尚未将此文件包含在包中。
一个解决方案是从网络上获取一个 FindCairo.cmake 文件,在项目的根目录中创建一个 cmake 目录,并在 CMakeLists.txt 额外的行

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

所以您从 CMakeLists.txt 中提取的代码片段看起来像:

cmake_minimum_required(VERSION 3.6)
project(HelloOpenGL)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(HelloOpenGL ${SOURCE_FILES})

#find_package(ImageMagick COMPONENTS Magick++)
#include_directories(${ImageMagick_INCLUDE_DIRS})
#target_link_libraries(HelloOpenGL ${ImageMagick_LIBRARIES})

find_package(Cairo)
include_directories(${Cairo_INCLUDE_DIRS})
target_link_libraries(HelloOpenGL ${Cairo_LIBRARIES})

如果您不使用已经存在的 FindCairo.cmake(例如,您安装的 Cairo 可能包含一个这样的文件),您将必须编写一个或找到另一种方法来包含该包。

关于c++ - 开罗图书馆和 Cmake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41636886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com