Using SDL2 with CMake

前端 未结 12 860
野性不改
野性不改 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:51

    For your information, I was able to successfully cmake and compile SDL2_ttf while linking to SDL2 source code.

    At first I was getting errors due to cmake not being able to locate SDL2, even though it was specified in cmake using the SLD2_DIR variable in cmake.

    It seems that for some reason cmaking SDL2 fails to create the SDL2Targets.cmake file which is searched for by SDL2_ttf

    If this is the case for you, get the SDL2Targets.cmake file from https://bugs.archlinux.org/task/57972 and modify the file like so:

    You can remove the following lines:

    get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
    get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
    get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
    get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
    if(_IMPORT_PREFIX STREQUAL "/")
        set(_IMPORT_PREFIX "")
    endif()
    

    and add this one:

    set(_IMPORT_PREFIX "C:/SDL2-2.0.12")
    

    Obviously change the filepath to the place you unpacked the SDL2 source code

    I'm not sure if this is exactly your issue, but there it is.

提交回复
热议问题