【发布时间】:2017-07-09 15:19:05
【问题描述】:
我正在 Windows 10 上使用 SDL2 和 CLion 构建一个测试项目。名为 HelloSDL 的项目基于 this tutorial,它只是创建一个窗口并打印“Hello World”。我正在使用来自here 的 FindSDL2.cmake 和 FindSDL2_ttf.cmake 脚本。我的 CMakeLists.txt 文件如下:
cmake_minimum_required(VERSION 3.6)
project(HelloSDL)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${HelloSDL_SOURCE_DIR}/cmake")
set(SDL2_PATH "C:\\SDL\\SDL2-2.0.5\\i686-w64-mingw32" CACHE PATH "The location to search for SDL2")
set(SDL2_TTF_PATH "C:\\SDL\\SDL2_ttf-2.0.14\\i686-w64-mingw32" CACHE PATH "The location to search for SDL2_TTF")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
find_package(SDL2_ttf REQUIRED)
include_directories(${SDL2_TTF_INCLUDE_DIR})
include_directories(include)
set(SOURCE_FILES main.cpp)
add_executable(HelloSDL ${SOURCE_FILES})
target_link_libraries(HelloSDL ${SDL2_LIBRARY} ${SDL2_TTF_LIBRARY})
该项目在 MinGW 下构建和运行非常好,但是当我尝试在 Cygwin 下构建它时出现链接错误:
CMakeFiles/HelloSDL.dir/main.cpp.o: In function `SDL_main':
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:97: undefined reference to `SDL_Init'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:102: undefined reference to `TTF_Init'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:104: undefined reference to `SDL_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:109: undefined reference to `SDL_CreateWindow'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:113: undefined reference to `TTF_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:114: undefined reference to `SDL_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:117: undefined reference to `SDL_CreateRenderer'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:121: undefined reference to `TTF_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:122: undefined reference to `SDL_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:133: undefined reference to `TTF_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:134: undefined reference to `SDL_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:140: undefined reference to `SDL_QueryTexture'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:148: undefined reference to `SDL_PollEvent'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:156: undefined reference to `SDL_RenderClear'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:160: undefined reference to `SDL_RenderPresent'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:164: undefined reference to `TTF_Quit'
/cygdrive/c/Users/Kieran/CLionProjects/HelloSDL/main.cpp:165: undefined reference to `SDL_Quit'
我没有很多经验,但对我来说这表明它没有链接到 SDL2 库。我很困惑为什么 CMake 输出表明它找到了 SDL2 库:
-- Found SDL2: C:/SDL/SDL2-2.0.5/i686-w64-mingw32/lib/libSDL2main.a;C:/SDL/SDL2-2.0.5/i686-w64-mingw32/lib/libSDL2.dll.a
如果尝试在 Cygwin 下编译它,我们将不胜感激。
【问题讨论】:
-
它创建了一个 mingw 库,而不是 cygwin 库。你安装了
libSDL2-devel和libSDL2_ttf-devel包了吗?
标签: windows cygwin mingw sdl-2 clion