cmake - 如何修复 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})
解决方案
推荐阅读
- meteor - 映射到自定义域仍显示 *.scapp.io
- reactjs - React 组件生命周期方法和远程 API 调用
- css - 来自 Angular 6 全局样式表的 TinyMCE content_css
- java - 你如何在corda中创建认股权证?
- csv - 在列上使用 awk 拆分 csv 文件
- xpath - 如何在给定起始页面中遵循基于 xpath 的规则在 Scrapy 中抓取多个链接?
- microsoft-teams - 如何在 MS Teams 中获取当前用户的可用性(可用、下班、离开...)?
- php - 如何使用 .htaccess 重写 HTTP 获取请求
- mongodb - 运行 MongoDB 查询时,如何扩展在 robo3t 中查看的文档数量?
- php - 如何在元标记 html 中添加 img src(带有 php 脚本)