0

I have a project (on linux) where I require glut and SDL. I already managed to properly link glut, but I still cant get SDL linked.

My CMake file looks like this:

cmake_minimum_required(VERSION 3.7)

project(ObjLoader)

add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS}  ${GLUT_INCLUDE_DIRS} )

target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})

When building the following exception is error occurs:

/opt/JetBrains/apps/CLion/ch-0/181.4668.70/bin/cmake/bin/cmake --build /home/void/Documents/Projects/ObjLoader/cmake-build-debug --target testas -- -j 2
[ 50%] Linking CXX executable testas
CMakeFiles/testas.dir/main.cpp.o: In function `main':
/home/user/Documents/Projects/ObjLoader/main.cpp:165: undefined reference to `SDL_Init'
/home/user/Documents/Projects/ObjLoader/main.cpp:166: undefined reference to `SDL_SetVideoMode'
/home/user/Documents/Projects/ObjLoader/main.cpp:173: undefined reference to `SDL_GetTicks'
/home/user/Documents/Projects/ObjLoader/main.cpp:174: undefined reference to `SDL_PollEvent'
/home/user/Documents/Projects/ObjLoader/main.cpp:184: undefined reference to `SDL_GL_SwapBuffers'
/home/user/Documents/Projects/ObjLoader/main.cpp:188: undefined reference to `SDL_GetTicks'
/home/user/Documents/Projects/ObjLoader/main.cpp:189: undefined reference to `SDL_GetTicks'
/home/user/Documents/Projects/ObjLoader/main.cpp:189: undefined reference to `SDL_Delay'
/home/user/Documents/Projects/ObjLoader/main.cpp:191: undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/testas.dir/build.make:100: testas] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/testas.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/testas.dir/rule] Error 2
make: *** [Makefile:118: testas] Error 2

but the same problem persists, When I try to link it as described here: How to use SDL2 and SDL_image with cmake the same problem persists. How can I properly include and link SDL in the CMake file above?

My attempt was this:

cmake_minimum_required(VERSION 3.7)

project(ObjLoader)

add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(SDL2 REQUIRED)

include_directories( ${OPENGL_INCLUDE_DIRS}  ${GLUT_INCLUDE_DIRS} ${SDL2_INCLUDE_DIRS})

target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${SDL2_LIBRARIES})

Doesnt change anything, same problem.

Kyu96
  • 1,159
  • 2
  • 17
  • 35
  • In the link step try ${SDL2_LIBRARY} – aram May 18 '18 at 16:14
  • @Aram When I try `target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )` I get : `CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: SDL2_LIBRARY linked by target "testas" in directory /home/user/Documents/Projects/ObjLoader` – Kyu96 May 18 '18 at 16:16
  • Wait, is this SDL 1.2 or SDL2? I'm asking because for example SDL_SetVideoMode, SDL_GL_SwapBuffers don't exist anymore in SDL2. Check the migration guide https://wiki.libsdl.org/MigrationGuide – aram May 18 '18 at 17:16
  • Just `SDL.h` is included so I assume v1. – Kyu96 May 18 '18 at 17:54
  • 1
    For SDL version 1 you may use [find_package(SDL)](https://cmake.org/cmake/help/v3.0/module/FindSDL.html) instead. – Tsyvarev May 18 '18 at 19:29

0 Answers0