I'm trying to make a SDL2 project in C++, which I've managed to get working using Clang++, I would just like a better way to receiving SDL2 libraries, and CMake seems like a good option here, with it's FetchContent feature. I first build with the MinGW Makefiles option, cmake -B build -G "MinGW Makefiles, and then then try to run make, but I get this error:
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: _deps/sdl2-build/libSDL2main.a(SDL_windows_main.c.obj):SDL_windows_ma:(.text+0x222): undefined reference to `SDL_main'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles\chip8.dir\build.make:152: chip8.exe] Error 1
make[1]: *** [CMakeFiles\Makefile2:136: CMakeFiles/chip8.dir/all] Error 2
make: *** [makefile:120: all] Error 2
My Windows build system looks as follows:
# FetchContent SDL2, SDL2_ttf
include(FetchContent)
set(FETCHCONTENT_QUIET NO)
set(SDL2_VERSION 2.30)
FetchContent_Declare(
SDL2
GIT_REPOSITORY https://github.com/libsdl-org/SDL
GIT_TAG release-2.30.0
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(SDL2)
include_directories(${SDL2_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} SDL2::SDL2main SDL2::SDL2-static)
For more details, here is the github page (it has sdl2_ttf stuff currently commented, to get SDL2 working first)