I am making a 64-bit game on Windows with SDL3, CMake and C++. I have managed, using my CMakeLists.txt, to dynamically link my program with SDL3. I am using the MinGW-w64 C++ Compiler, and I do not want the user to install SDL3.
My CMakeLists.txt is this:
cmake_minimum_required(VERSION 3.20)
project(space_adventure CXX)
set(CMAKE_PREFIX_PATH "C:/sdl3")
find_package(SDL3 REQUIRED CONFIG)
file(GLOB_RECURSE "sources" "src/*.cpp")
add_executable(space_adventure ${sources})
target_link_libraries(space_adventure PRIVATE SDL3::SDL3)
And I have attempted this:
cmake_minimum_required(VERSION 3.20)
project(space_adventure CXX)
set(CMAKE_PREFIX_PATH "C:/sdl3")
find_package(SDL3-static REQUIRED CONFIG)
file(GLOB_RECURSE "sources" "src/*.cpp")
add_executable(space_adventure ${sources})
target_link_libraries(space_adventure PRIVATE SDL3::SDL3-static)
I received this error when trying the second one:
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "FindSDL3-static.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"SDL3-static", but CMake did not find one.
Could not find a package configuration file provided by "SDL3-static" with
any of the following names:
SDL3-staticConfig.cmake
sdl3-static-config.cmake
Add the installation prefix of "SDL3-static" to CMAKE_PREFIX_PATH or set
"SDL3-static_DIR" to a directory containing one of the above files. If
"SDL3-static" provides a separate development package or SDK, be sure it
has been installed.
I assume I have installed the wrong package. Namely, I installed and unzipped SDL3-3.2.28-win32-x86.zip from release 3.2.28 into C:/SDL3, which is a pre-built package. Should I use SDL3-devel-3.2.28-mingw.tar.gz? As I believe it is designed for the MinGW-w64 C++ compiler, this could be a solution. However I'm not quite sure.
1 Answer 1
If you are using MinGW I recommend that you use msys2 (which includes the compiler and thousands of open source packages in its package management) and have pacman install the ucrt64 version: https://packages.msys2.org/packages/mingw-w64-ucrt-x86_64-sdl3 the install instructions are in the middle of the page: pacman -S mingw-w64-ucrt-x86_64-sdl3
This question can help you install msys2: How can I install MinGW-w64 and MSYS2?
pacman -S mingw-w64-ucrt-x86_64-sdl3target_link_librariesand point to the static.afile you compiled, along with usingtarget_include_directoriesto provide the header paths.