How to use sdl in Clion

0

I'm reasonably new to C ++, and I do not know how to use sdl in Clion. I've tried it in several ways, it's currently like this:

CMakeLists:

project(cppsdl)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmingw32")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")

set(SDL_ROOT "C:/CppLibs/SDL2-2.0.4/i686-w64-mingw32")
include_directories(${SDL_ROOT}/include)
link_directories(${SDL_ROOT}/lib)

set(SOURCE_FILES main.cpp)
add_executable(cppsdl ${SOURCE_FILES})

target_link_libraries(cppsdl SDL2main SDL2)

main.cpp:

#include <iostream>
#include "SDL2/SDL.h"

int main(){
    if (SDL_Init(SDL_INIT_VIDEO) != 0){
        std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
        return 1;
    }
    SDL_Quit();
    return 0;
}

Returns the following error:

 C:/CppLibs/SDL2-2.0.4/i686-w64-mingw32/lib/libSDL2main.a(SDL_windows_main.o): In function 'main_utf8':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/main/windows/SDL_windows_main.c:126: undefined reference to 'SDL_main'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/main/windows/SDL_windows_main.c:126: undefined reference to 'SDL_main'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/main/windows/SDL_windows_main.c:126: undefined reference to 'SDL_main'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [cppsdl.exe] Error 1
CMakeFiles\cppsdl.dir\build.make:87: recipe for target 'cppsdl.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/cppsdl.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/cppsdl.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/cppsdl.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/cppsdl.dir/rule] Error 2
mingw32-make.exe: *** [cppsdl] Error 2
Makefile:108: recipe for target 'cppsdl' failed
    
asked by anonymous 21.04.2016 / 22:47

1 answer

3

The best way is to use FindSDL2.cmake to download it and place it in the same project folder:

You can find it here: link

    
19.05.2016 / 19:03