mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-08 08:10:30 -10:00
build: drop SDL's WinMain shim lib (-lSDL*main) from the link
The SDL_MAIN_HANDLED change (decdce0) stopped SDL.h from renaming our
main to SDL_main, but the Windows CXX_BUILD link still failed with:
libSDL2main.a(SDL_windows_main.c.obj): undefined reference to SDL_main
Cause: SDL2_LIBS is the raw output of 'pkg-config --libs sdl2', which
on MSYS2/MinGW is '-lmingw32 -lSDL2main -lSDL2'. libmingw32 has an
undefined reference to WinMain; when -lSDL2main is on the link line it
satisfies that reference with SDL2main's own WinMain, whose object is
therefore pulled in -- and that WinMain hard-calls SDL_main. Now that
main correctly stays main (SDL_MAIN_HANDLED), SDL_main does not exist,
so the reference dangles.
The SDL*main libraries exist solely to provide that WinMain shim,
which we have explicitly opted out of. Filter -lSDL*main / -lSDLmain /
-lSDL_main out of SDL_LIBS / SDL2_LIBS / SDL3_LIBS before adding them
to LIBS. -lmingw32 (real WinMain -> main bridge) and -lSDL2 (the
actual library) are kept; only the shim is removed.
Verified: $(filter-out -lSDL2main ...,$(SDL2_LIBS)) turns
'-lmingw32 -lSDL2main -lSDL2' into '-lmingw32 -lSDL2'.
Completes the SDL entry-point fix begun in decdce0; together they let
the Windows CXX_BUILD=1 link resolve. Independent of CXX_BUILD this is
also the correct linkage for an app that owns its own entry point.
This commit is contained in:
1 parent
decdce0439
commit
80f343b494
1 file changed
+12
-3
+12
-3
@@ -1685,7 +1685,13 @@ ifeq ($(HAVE_SDL3), 1)
|
||||
SDL3_CFLAGS = $(shell pkg-config sdl3 --cflags)
|
||||
SDL3_LIBS = $(shell pkg-config sdl3 --libs)
|
||||
DEF_FLAGS += $(SDL3_CFLAGS)
|
||||
LIBS += $(SDL3_LIBS)
|
||||
# RetroArch supplies its own entry point and sets SDL_MAIN_HANDLED
|
||||
# (see retroarch.c), so SDL's WinMain shim library (-lSDL3main /
|
||||
# -lSDLmain, pulled in automatically by pkg-config --libs on
|
||||
# Windows/MSYS2) is both unnecessary and harmful: its WinMain
|
||||
# references SDL_main, which no longer exists once main stays main.
|
||||
# Filter it out.
|
||||
LIBS += $(filter-out -lSDL3main -lSDLmain -lSDL_main,$(SDL3_LIBS))
|
||||
DEFINES += -DHAVE_SDL3
|
||||
OBJ += input/drivers_joypad/sdl3_joypad.o
|
||||
else ifeq ($(HAVE_SDL2), 1)
|
||||
@@ -1693,12 +1699,15 @@ else ifeq ($(HAVE_SDL2), 1)
|
||||
OBJ += gfx/drivers/sdl2_gfx.o \
|
||||
gfx/common/sdl2_common.o
|
||||
DEF_FLAGS += $(SDL2_CFLAGS)
|
||||
LIBS += $(SDL2_LIBS)
|
||||
# See the SDL3 note above: drop SDL's WinMain shim lib, we set
|
||||
# SDL_MAIN_HANDLED and provide our own entry point.
|
||||
LIBS += $(filter-out -lSDL2main -lSDLmain -lSDL_main,$(SDL2_LIBS))
|
||||
else ifeq ($(HAVE_SDL), 1)
|
||||
HAVE_SDL_COMMON = 1
|
||||
OBJ += gfx/drivers/sdl_gfx.o
|
||||
DEF_FLAGS += $(SDL_CFLAGS)
|
||||
LIBS += $(SDL_LIBS)
|
||||
# See the SDL3 note above: drop SDL's WinMain shim lib.
|
||||
LIBS += $(filter-out -lSDLmain -lSDL_main,$(SDL_LIBS))
|
||||
else ifeq ($(HAVE_SDL_DINGUX), 1)
|
||||
HAVE_SDL_COMMON = 1
|
||||
DEF_FLAGS += -DHAVE_SDL -DHAVE_SDL_DINGUX
|
||||
|
||||
Reference in new issue
Block a user