2017-10-10 2 views
0

Clion을 SDL2와 함께 사용하고 싶고 많은 테스트를 거친 후에 이미 오류가 있습니다.Clion Cmake & SDL2

내 CmakeLists.txt있다 :

cmake_minimum_required(VERSION 3.8) 
project(sdl2-test) 

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmingw32") 
#set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") 
set(CMAKE_CXX_STANDARD 11) 
include_directories(${PROJECT_SOURCE_DIR}/include) 
link_directories(${PROJECT_SOURCE_DIR}/lib) 

set(SOURCE_FILES main.cpp) 
add_executable(sdl2-test ${SOURCE_FILES}) 

target_link_libraries(sdl2-test SDL2main SDL2) 

내 MAIN.CPP

#include <iostream> 

#include "include/SDL2/SDL.h" 

using namespace std; 

int main(int argc, char** argv) { 
    if(SDL_Init(SDL_INIT_EVERYTHING) == -1){ 
     cout << "Something went wrong! " << SDL_GetError() << endl; 
    } 

    SDL_Window* window = SDL_CreateWindow("SDL_Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 
             1280, 720, SDL_WINDOW_OPENGL); 
    if(window == nullptr){ 
     cout << "Something also went wrong here" << endl; 
    } 

    SDL_Delay(2000); 
    SDL_Quit(); 
    return 0; 

} 

하지만 난 내 프로젝트 cmake를 빌드 할 때 분명히 Cmake 작업은 찾을 수 있지만 몇 가지 오류 haave :

C:\Users\paulp\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\172.4343.16 \bin\cmake\bin\cmake.exe --build C:\Users\paulp\CLionProjects\sdl2-test\cmake- build-debug --target sdl2-test -- -j 4 
[ 50%] Building CXX object CMakeFiles/sdl2-test.dir/main.cpp.obj 
[100%] Linking CXX executable sdl2-test.exe 
CMakeFiles\sdl2-test.dir/objects.a(main.cpp.obj): In function `SDL_main': 
C:/Users/paulp/CLionProjects/sdl2-test/main.cpp:8: undefined reference to `SDL_Init' 
C:/Users/paulp/CLionProjects/sdl2-test/main.cpp:9: undefined reference to `SDL_GetError' 
C:/Users/paulp/CLionProjects/sdl2-test/main.cpp:13: undefined reference to `SDL_CreateWindow' 
C:/Users/paulp/CLionProjects/sdl2-test/main.cpp:18: undefined reference to `SDL_Delay' 
C:/Users/paulp/CLionProjects/sdl2-test/main.cpp:19: undefined reference to `SDL_Quit' 
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `[email protected]' 
collect2.exe: error: ld returned 1 exit status 
CMakeFiles\sdl2-test.dir\build.make:96: recipe for target 'sdl2-test.exe' failed 
mingw32-make.exe[3]: *** [sdl2-test.exe] Error 1 
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/sdl2-test.dir/all' failed 
mingw32-make.exe[2]: *** [CMakeFiles/sdl2-test.dir/all] Error 2 
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/sdl2-test.dir/rule' failed 
mingw32-make.exe[1]: *** [CMakeFiles/sdl2-test.dir/rule] Error 2 
mingw32-make.exe: *** [sdl2-test] Error 2 
Makefile:117: recipe for target 'sdl2-test' failed 

수정 방법은 무엇입니까?

+0

것 같아요 당신은 오른쪽 mingw devel 버전 – user1754322

+0

을 다운로드했습니다. SDL2-devel-2.0.6-mingw.tar.gz를 다운로드하고 mingw 5.0을 사용합니다. –

답변

0

링커가 sdl2-lib의 위치를 ​​알지 못하기 때문에 응용 프로그램 연결이 실패했습니다.

당신은 당신의 cmake 파일뿐만 아니라 SDL2-라이브러리를 검색하고 메이크에 위치를 추가해야합니다

find_file(SDL2_INCLUDE_DIR NAME SDL.h HINTS SDL2) 
find_library(SDL2_LIBRARY NAME SDL2) 
add_executable(ChickenShooter main.cpp) 
target_include_directories(ChickenShooter ${SDL2_INCLUDE_DIR}) 
target_link_libraries(ChickenShooter ${SDL2_LIBRARY}) 
당신은뿐만 아니라이 게시물에 볼 수

: How to dins SDL2 via cmake

+0

CMakeLists.txt의 CMake 오류 : 18 (target_include_directories) : 잘못된 인수로 target_include_directories가 호출되었습니다. –

+0

어떻게 makefile에 위치를 추가 할 수 있습니까? –

+0

내 예를 들어 target_include_directories (ChickenShooter $ {SDL2_INCLUDE_DIR}) target_link_libraries (치킨 슈터 $ {SDL2_LIBRARY})로 완료 – KimKulling

관련 문제