Skip to content

Commit 6bc5fc6

Browse files
committed
Fixed the desktop version on Windows
1 parent 273f8fe commit 6bc5fc6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ FetchContent_Declare(
2727

2828
# Only build the shared library for SDL2
2929
set(BUILD_SHARED_LIBS ON)
30-
set(SDL2_DISABLE_SDL2MAIN ON CACHE BOOL "" FORCE)
3130
set(SDL2_DISABLE_UNINSTALL ON CACHE BOOL "" FORCE)
3231
set(SDL_TEST_ENABLED_BY_DEFAULT OFF)
3332

33+
# SDL main is only needed for desktop apps (more specifically Windows)
34+
if (IOS OR ANDROID)
35+
set(SDL2_DISABLE_SDL2MAIN ON CACHE BOOL "" FORCE)
36+
endif()
37+
3438
# Make sure debug libs have the same name as release ones
3539
set(SDL_CMAKE_DEBUG_POSTFIX "")
3640
set(SDL2IMAGE_DEBUG_POSTFIX "")
@@ -71,6 +75,7 @@ elseif(ANDROID)
7175
add_library( ${PROJECT_NAME} SHARED ${SOURCE_FILES})
7276
else()
7377
add_executable( ${PROJECT_NAME} ${SOURCE_FILES} )
78+
target_link_libraries( ${PROJECT_NAME} SDL2main )
7479
endif()
7580

7681
target_link_libraries( ${PROJECT_NAME} SDL2 SDL2_image )

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ cmake ..
2828
cmake --build .
2929
cd ..
3030
./build/hello_sdl2
31-
```
31+
```
32+
33+
The binary might be under its specific configuration, like `build/Debug/hello_sdl2` or `build/Release/hello_sdl2`

0 commit comments

Comments
 (0)