CMake find_package SDL2_ttf 在 MSYS2 + MinGW-w64 上失败

问题描述 投票:0回答:1

我正在尝试在 Windows 上的 MinGW 下构建一个 SDL2 项目。在 Arch Linux 上构建很顺利,但是当我尝试在 Windows 上构建时出现此错误:

CMake Error at CMakeLists.txt:14 (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.

我已经安装了

mingw-w64-x86_64-SDL2
mingw-w64-x86_64-SDL2_ttf
软件包。 CMake 配置似乎也已正确安装(在
/mingw64/lib/cmake/SDL2_ttf/sdl2_ttf-config.cmake
中)

我使用简单的 CMake 3.16 配置,具有

find_package
:

cmake_minimum_required(VERSION 3.16)
project(project VERSION 0.0.1)

file(GLOB SOURCE_FILES
    src/[a-z]*.c
)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED YES)
set(CMAKE_C_EXTENSIONS OFF)

find_package(SDL2 REQUIRED)
find_package(SDL2_ttf REQUIRED)

set(C_FLAGS "-rdynamic")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}")

ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
                      SDL2::SDL2
                      SDL2_ttf
)
windows cmake mingw sdl-2 find-package
1个回答
0
投票

由于某种原因,MSYS 将

sdl2-config.cmake
安装在
/usr/lib/cmake/SDL2/
下,而
sdl2_ttf-config.cmake
只存在于
msys64
目录中。

将 cmake 配置链接到正确的目录中已经解决了问题。

ln -s /mingw64/lib/cmake/SDL2_ttf /usr/lib/cmake/SDL2_ttf
© www.soinside.com 2019 - 2024. All rights reserved.