SDL2 Undefined Reference (native MinGW-w64 and MXE)

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

SDL2 Undefined Reference (native MinGW-w64 and MXE)

Last thing I want to do is to ask *this* one question which has been asked so many times. Anyways...

I can't get my SDL2 game to link for Windows (though it compiles and links perfectly on Linux). The errors are


C:\msys64\tmp\ccXMO8av.o: In function `SDL_main':
C:\msys64\home\naman\ascend/src/game/ascend.c:102: undefined reference to `SDL_LogInfo'
C:\msys64\home\naman\ascend/src/game/ascend.c:104: undefined reference to `SDL_LogInfo'
C:\msys64\home\naman\ascend/src/game/ascend.c:114: undefined reference to `SDL_LogInfo'
C:\msys64\home\naman\ascend/src/game/ascend.c:116: undefined reference to `SDL_GL_DeleteContext'
C:\msys64\home\naman\ascend/src/game/ascend.c:117: undefined reference to `SDL_DestroyWindow'
C:\msys64\home\naman\ascend/src/game/ascend.c:118: undefined reference to `SDL_Quit'

and so on for ~50 more lines.

On MXE while cross-compiling, using $(sdl-config --libs) didn't work (same errors) but $(sdl-config --static-libs) did. Fine. Whatever.
Now, on Windows 7 64-bit using MinGW-w64 (installed through MSYS2), that doesn't work either through gcc or clang (on 32-bit "namespace" i.e. /mingw32). SDL2 was installed using packages mingw-w64-i686-SDL2

The compilation command I am using is:



CFLAGS="-g3 -I${INCINDPATH} -I${INCDEPPATH} -std=c99 -O1 $(sdl2-config --cflags)"
LDFLAGS="-lm $(sdl2-config --static-libs)"

which expands to

CLFAGS="-g3 -Iinclude/platform_independent -Iinclude/platform_dependent/windows -std=c99 -O1 -I/mingw32/include/SDL2 -Dmain=SDL_main"
LDFLAGS="-lm -L/mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--no-undefined -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc"

Using $(sdl-config --libs) instead of --static-libs expand to:

LDFLAGS="-lm -L/mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows"

The paths generated by sdl-config are correct; and according to numerous answers all around the internet, so are the flags. Only weird thing I can find is that MSYS2 doesn't install file in /mingw32/lib. However, it doesn't work even if if I manually change these paths appropriately to point to SDL2-devel-2.0.4-mingw.tar.gz's content.

What else should I try?

SDL mailing list
[hidden email]