Linker error with SDL2 and CMake

This page summarizes the projects mentioned and recommended in the original post on /r/learnprogramming

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • SDL

    Simple Directmedia Layer

  • cmake_minimum_required(VERSION 3.16) project(P1_PC) add_executable(P1_PC src/main.cpp) find_package(Vulkan REQUIRED) if(NOT Vulkan_FOUND) message(FATAL_ERROR "Vulkan not found. Download at https://www.vulkan.org/") endif() find_package(SDL2 QUIET) if(NOT SDL2_FOUND) include(FetchContent) FETCHCONTENT_DECLARE( SDL2 GIT_REPOSITORY https://github.com/libsdl-org/SDL GIT_TAG release-2.26.3 ) FetchContent_GetProperties(SDL2) if (NOT sdl2_POPULATED) set(FETCHCONTENT_QUIET NO) FetchContent_Populate(SDL2) set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(BUILD_GAMES OFF CACHE BOOL "" FORCE) add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR}) endif() endif() target_include_directories(${PROJECT_NAME} PRIVATE ${Vulkan_INCLUDE_DIRS} PRIVATE ${SDL2_SOURCE_DIR}) target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARIES} SDL2-static SDL2main SDL2) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)

  • Vulkan-Headers

    Vulkan header files and API registry

  • cmake_minimum_required(VERSION 3.16) project(P1_PC) add_executable(P1_PC src/main.cpp) find_package(Vulkan REQUIRED) if(NOT Vulkan_FOUND) message(FATAL_ERROR "Vulkan not found. Download at https://www.vulkan.org/") endif() find_package(SDL2 QUIET) if(NOT SDL2_FOUND) include(FetchContent) FETCHCONTENT_DECLARE( SDL2 GIT_REPOSITORY https://github.com/libsdl-org/SDL GIT_TAG release-2.26.3 ) FetchContent_GetProperties(SDL2) if (NOT sdl2_POPULATED) set(FETCHCONTENT_QUIET NO) FetchContent_Populate(SDL2) set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(BUILD_GAMES OFF CACHE BOOL "" FORCE) add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR}) endif() endif() target_include_directories(${PROJECT_NAME} PRIVATE ${Vulkan_INCLUDE_DIRS} PRIVATE ${SDL2_SOURCE_DIR}) target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARIES} SDL2-static SDL2main SDL2) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts