首页 > 解决方案 > 如何修复 CMakeList 以使用 SDL_image 构建项目?

问题描述

我尝试使用 SDL2_image 构建项目,但出现这样的错误:

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

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

SDL2_imageConfig.cmake
sdl2_image-config.cmake

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

如果用 CTRL+F5 编译项目,它工作正常。

我使用 ubuntu 20.04,Clion,也添加FindSDL2_image.cmake到 cmake/Modules。有人可以帮忙吗?

我的 CMakeList.txt:

cmake_minimum_required(VERSION 3.17)
project(POng2)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)


include_directories(${SDL2_INCLUDE_DIR}
        ${SDL2_IMAGE_INCLUDE_DIR}
        ${SDL2_TTF_INCLUDE_DIR})

add_executable(POng2 main.cpp Game.h Game.cpp Paddle.h Paddle.cpp Entity.h Entity.cpp Ball.h 
               Ball.cpp Board.h Board.cpp Score.h Score.cpp)

target_link_libraries(POng2 ${SDL2_LIBRARY}
        ${SDL2_IMAGE_LIBRARIES}
        ${SDL2_TTF_LIBRARIES})

标签: cmakesdl-2clion

解决方案


推荐阅读