From 7072f999d00ea1fdebea2abebdd16a82c7ea130d Mon Sep 17 00:00:00 2001 From: LiHaohua Date: Wed, 3 Jun 2026 14:19:29 +0800 Subject: [PATCH] ci(windows): link SDL2main before SDL2 (single-pass MinGW ld) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing SDL2_image exposed a latent link-order bug: libSDL2main.a references SDL symbols (SDL_strlen, SDL_SetMainReady, …) but was linked after libSDL2. MinGW's ld is single-pass, so the references went unresolved. SDL2_image at the tail used to re-pull the SDL archive and mask it. Put SDL2main before SDL2. macOS (static path) unaffected. --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 084b321..4e85070 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,6 +304,12 @@ if(APPLE AND EMU_MACOS_STATIC_DEPS) ) else() # Dynamic linkage (Linux, Windows, or macOS with -DEMU_MACOS_STATIC_DEPS=OFF) + # SDL2main must come BEFORE SDL2: it references SDL symbols, and MinGW's ld + # is a single-pass linker. (Previously SDL2_image at the tail happened to + # re-pull the SDL symbols; removing it exposed the latent ordering bug.) + if(TARGET SDL2::SDL2main) + target_link_libraries(cardputer-emu PRIVATE SDL2::SDL2main) + endif() if(TARGET SDL2::SDL2) target_link_libraries(cardputer-emu PRIVATE SDL2::SDL2) elseif(TARGET SDL2::SDL2-static) @@ -312,9 +318,6 @@ else() target_include_directories(cardputer-emu PRIVATE ${SDL2_INCLUDE_DIRS}) target_link_libraries(cardputer-emu PRIVATE ${SDL2_LIBRARIES}) endif() - if(TARGET SDL2::SDL2main) - target_link_libraries(cardputer-emu PRIVATE SDL2::SDL2main) - endif() # Freetype (needed by LVGL) if(FREETYPE_FOUND AND FREETYPE_LINK_LIBRARIES) target_link_libraries(cardputer-emu PRIVATE ${FREETYPE_LINK_LIBRARIES})