0
我在Windows 10上使用SDL2和CLion構建測試項目。名爲HelloSDL的項目基於this tutorial,並創建一個窗口並打印出「Hello World」。我使用here的FindSDL2.cmake和FindSDL2_ttf.cmake腳本。我的CMakeLists.txt文件如下:SDL2項目建立在MinGW上但不是Cygwin使用CLion
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的一個。你有沒有安裝\t'libSDL2-devel'和'libSDL2_ttf-devel'軟件包? – matzeri