Home >Backend Development >C++ >How to Resolve SDL2 Header Inclusion Problems with CMake?
Problem:
When developing an SDL2 project in CLion, "#include
Solution:
For Linux Systems:
<code class="cmake">find_package(SDL2 REQUIRED) include_directories(SDL2Test ${SDL2_INCLUDE_DIRS}) add_executable(SDL2Test Main.cpp) target_link_libraries(SDL2Test ${SDL2_LIBRARIES})</code>
For Windows Systems:
<code class="cmake">set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include") # Support both 32 and 64 bit builds if (${CMAKE_SIZEOF_VOID_P} MATCHES 8) set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2main.lib") else () set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2main.lib") endif () string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)</code>
Post-Solution:
SDL2 headers can now be included simply by writing #include "SDL.h" in your code.
The above is the detailed content of How to Resolve SDL2 Header Inclusion Problems with CMake?. For more information, please follow other related articles on the PHP Chinese website!