SDL2 项目基于 MinGW 而不是使用 CLion 的 Cygwin
SDL2 project builds on MinGW but not Cygwin using CLion
我正在 Windows 10 上使用 SDL2 和 CLion 构建一个测试项目。名为 HelloSDL 的项目基于 this tutorial, and just creates a window and prints "Hello World". I'm using the FindSDL2.cmake and FindSDL2_ttf.cmake scripts from here。我的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 下进行编译,我们将不胜感激。
首先,您需要使用 Cygwin 的库 (libSDL2*-devel),而不是您为 MinGW 下载的库,您还需要使用 CMake 使用 MSYS 格式生成 Makefile。
cmake -G "MSYS Makefiles"
我正在 Windows 10 上使用 SDL2 和 CLion 构建一个测试项目。名为 HelloSDL 的项目基于 this tutorial, and just creates a window and prints "Hello World". I'm using the FindSDL2.cmake and FindSDL2_ttf.cmake scripts from here。我的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 下进行编译,我们将不胜感激。
首先,您需要使用 Cygwin 的库 (libSDL2*-devel),而不是您为 MinGW 下载的库,您还需要使用 CMake 使用 MSYS 格式生成 Makefile。
cmake -G "MSYS Makefiles"