gpt4 book ai didi

c++ - CMake无法找到SDL2_ttf,我正在尝试以与SDL2相同的方式链接它,并且两者都已正确安装在Ubuntu 18.04上

转载 作者:行者123 更新时间:2023-12-02 10:23:31 27 4
gpt4 key购买 nike

我得到错误:

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

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

SDL2_ttfConfig.cmake
sdl2_ttf-config.cmake

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

这是我的cmake文件的样子:
cmake_minimum_required(VERSION 3.14)
project(Smithereens)

set(CMAKE_CXX_STANDARD 17)

add_executable(Smithereens main.cpp)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

find_package(SDL2_ttf REQUIRED)
include_directories(${SDL2_ttf_INCLUDE_DIRS})

target_link_libraries(Smithereens ${SDL2_LIBRARIES} ${SDL2_ttf_LIBRARIES})

SDL2和SDL2_ttf都安装在我的计算机上,我确定连接不正确,学习CMake对我来说是一个巨大的麻烦。

最佳答案

这对我来说很好,Ubuntu 18.04。

INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
PKG_SEARCH_MODULE(SDL2TTF REQUIRED SDL2_ttf>=2.0.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SOURCE_FILES main.cpp)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})

target_include_directories(${PROJECT_NAME} PRIVATE
include ${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${SDL2TTF_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES})

关于c++ - CMake无法找到SDL2_ttf,我正在尝试以与SDL2相同的方式链接它,并且两者都已正确安装在Ubuntu 18.04上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58107854/

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