0

I'm trying CMake for the first time. When I run cmake from the command line everything seems ok:

alex@mileena:~/Projects/SDLTutorial/_build$ cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/Projects/SDLTutorial/_build

But when I run make, I get undefined references to all SDL functions. I've included SDL.h.

alex@mileena:~/Projects/SDLTutorial/_build$ make                  
Linking CXX executable SDLTutorial
CMakeFiles/SDLTutorial.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x15): undefined reference to `SDL_Init'
main.cpp:(.text+0x43): undefined reference to `SDL_CreateWindow'
main.cpp:(.text+0x6f): undefined reference to `SDL_CreateRenderer'
main.cpp:(.text+0xa3): undefined reference to `SDL_SetRenderDrawColor'
main.cpp:(.text+0xb2): undefined reference to `SDL_RenderClear'
main.cpp:(.text+0xc1): undefined reference to `SDL_RenderPresent'
main.cpp:(.text+0xcb): undefined reference to `SDL_Delay'
main.cpp:(.text+0xd0): undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
CMakeFiles/SDLTutorial.dir/build.make:85: recipe for target 'SDLTutorial' failed
make[2]: *** [SDLTutorial] Error 1

These are the contents of CMakeLists.txt. Am I including the library correctly?

cmake_minimum_required(VERSION 2.8)
project(SDLTutorial)
add_executable(SDLTutorial main.cpp)
find_library(SDL REQUIRED)
if (SDL_FOUND)
    include_directories(${SDL_INCLUDE_DIR})
    target_link_libraries(SDLTutorial ${SDL_LIBRARY})
endif (SDL_FOUND)
install(TARGETS SDLTutorial DESTINATION bin) 
ShrimpCrackers
  • 4,388
  • 17
  • 50
  • 76
  • With a standard "makefile", all you have to do is 1) specify `-L/path/to/libSDL`, and 2) specify `-lSDL`. For CMake, look [here](http://duganchen.ca/building-sdl2-programs-with-cmake-and-pkgconfig/) or [here](http://content.gpwiki.org/index.php/SDL:Tutorials:Setup) – paulsm4 Oct 11 '15 at 06:38
  • 2
    Comapre http://stackoverflow.com/questions/23850472/how-to-use-sdl2-and-sdl-image-with-cmake – usr1234567 Oct 11 '15 at 08:26
  • Check out my answer to [this similar question](http://stackoverflow.com/a/32959305). It's for windows/mingw, but you can easily adapt it to Linux/gcc as well. – maddouri Oct 11 '15 at 23:57

0 Answers0