0

I'm setting up my programming environment in VSCode, and coming from VS where everything is automated (mostly), I'm finding that CMake is giving me an exceptional amount of trouble. I'm attempting to setup SDL2 by using the libraries that came with the VulkanSDK, but I'm getting linker error upon linker error. I've spent the last three or four days scouring the internet, with none of the solutions that are present on Stack Overflow or any other medium having worked.

Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(P2_PR VERSION 0.1.0)


add_executable(P2_PR main.cpp)

find_package(Vulkan QUIET)
if(NOT Vulkan_FOUND)
    message(FATAL_ERROR "Vulkan not found. Download at 
https://www.vulkan.org/")
endif()

include_directories(${Vulkan_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARIES} 
${SDL2_LIBRARIES} ${GLM_LIBRARIES})

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)

It is successfully locating the directories, and I am able to include the libs without issue. No squiggly line, no "can't find .h". It seems to be exclusively a linker issue, and I fear that my lack of CMake experience is making deciphering the problem impossible.

Not every SDL reference is complained about. For instance; I am able to create a window pointer using the SDL_Window reference, however the use of any SDL-specific functions return an error.

This works:

int main(int argc, char** argv) {    
    SDL_Window* window;
    return 0;
}

This does not work, and returns the error Undefined Reference to: SDL_PollEvent:

int main(int argc, char** argv) {    
    SDL_Window* window;
    SDL_PollEvent(nullptr);
    return 0;
}

I can confirm that vulkan and GLM both work properly. It's simply SDL2 giving me the trouble. I would greatly appreciate any help anyone here has to offer.

273K
  • 29,503
  • 10
  • 41
  • 64
Satchel
  • 1
  • 2
  • Where/how is `SDL2_LIBRARIES` being defined? It's not in [the list of result variables for the `FindVulkan` modules](https://cmake.org/cmake/help/latest/module/FindVulkan.html#result-variables). Have you actually shown enough of your CMake config to reproduce this issue? Is this a [mre]? Is it even defined to anything? As far as I know, it's not an error in CMake to use an undefined variable (it will just be the empty string when used). What do you see if you `message("SDL2_LIBRARIES: ${SDL2_LIBRARIES}")`? – starball Feb 27 '23 at 00:33
  • I have posted the entirety of my CMake config. When doing what you said, and attempting to print off the actual SDL2 libs, it does in fact return an empty string. The SDL2 libs are found within the Vulkan lib directory. It appears I just don't know how to point to them properly. – Satchel Feb 27 '23 at 00:40

0 Answers0