Stroumphette-ES
Stroumphette-ES

Reputation: 109

Install SDL in CLION

I try to install SDL in Clion with a C project. I dowload the ZIP SDL ( librairies dev ), I add the include and lib folder and I change my CMakeList.txt like :

cmake_minimum_required(VERSION 3.8)
project(Projet1)

set(CMAKE_C_STANDARD 99)
include_directories( ${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)

set(SOURCE_FILES main.c include lib)
add_executable(Projet1 ${SOURCE_FILES})

I have this :

enter image description here

Is it the good configuration?

Upvotes: 1

Views: 2329

Answers (1)

dustinroepsch
dustinroepsch

Reputation: 1160

This problem is actually separate from CLion, you'll need to install SDL in whatever way is supported by or OS (win32 exe, apt-get, brew, etc).

There is a cmake module called FindSDL2 which is basically the de-facto standard for making cmake include SDL2. You'll want to download this file and put it in a folder called cmake in the root of your project.

After that, you'll want to modify your CMakeLists.txt file to be something like this :

cmake_minimum_required(VERSION 2.8)
project(Project1)

# includes cmake/FindSDL2.cmake
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})

set(SOURCE_FILES src/main.cpp)

add_executable(Project1 ${SOURCE_FILES})
target_link_libraries(Project1 ${SDL2_LIBRARY})

This answer is paraphrased from this blog post.

Upvotes: 4

Related Questions