Using SDL2 with CMake

前端 未结 12 859
野性不改
野性不改 2020-11-28 10:47

I\'m trying to use CLion to create a SDL2 project. The problem is that the SDL headers can\'t be found when using #include\'s.

My CMakeLists.txt file:



        
12条回答
  •  难免孤独
    2020-11-28 10:53

    Don't set the path to SDL2 by hand. Use the proper find command which uses FindSDL. Should look like:

    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})    
    

    If SDL2 is not found, you have to add the path to SDL2 to CMAKE_PREFIX_PATH, that's the place where CMake looks for installed software.

    If you can use Pkg-config, its use might be easier, see How to use SDL2 and SDL_image with cmake

    If you feel more comfortable to use a FindSDL2.cmake file similar to FindSDL.cmake provided by CMake, see https://brendanwhitfield.wordpress.com/2015/02/26/using-cmake-with-sdl2/

提交回复
热议问题