問題:
在CLion 中開發SDL2 專案時,「#include < ;SDL.h>"找不到必要的頭檔。
解決方案:
Linux 系統:
<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>
對於Windows 系統:
<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>
後解決方案:
SDL2現在只需在程式碼中寫入 #include "SDL.h" 即可包含標頭。以上是如何使用 CMake 解決 SDL2 標頭包含問題?的詳細內容。更多資訊請關注PHP中文網其他相關文章!