Compile MinGW SDL2


#1

Hi,
I want to compile MinGW SDL2 (from Mercuria for latest updates).
I want static *.a files too.
I tried to compile with mysys and cygwin but after compiling when I use *.a file I obtain unefined reference to ERROR…
*.a files from SDL2-devel-2.0.8-mingw.tar.gz pack on official site works perfectly… but this is outdated for me.
Can you help me?


#2

I tried to compile with cygwin, mysys for mingw, and mingw w64. No work…


#3

Example for Cygwin compiling using --host=i686-w64-mingw32

after compile I have libSDL2.a, but when I compile my project I obtain:

…/tools/win-sdk/lib\libSDL2.a(SDL_iconv.o): In function SDL_iconv_REAL': /cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:72: undefined reference toiconv’
…/tools/win-sdk/lib\libSDL2.a(SDL_iconv.o): In function SDL_iconv_open_REAL': /cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:54: undefined reference toiconv_open’
…/tools/win-sdk/lib\libSDL2.a(SDL_iconv.o): In function SDL_iconv_REAL': /cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:72: undefined reference toiconv’
…/tools/win-sdk/lib\libSDL2.a(SDL_iconv.o): In function SDL_iconv_close_REAL': /cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:60: undefined reference toiconv_close’
/cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:60: undefined reference to iconv_close' ../tools/win-sdk/lib\libSDL2.a(SDL_iconv.o): In functionSDL_iconv_open_REAL’:
/cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:54: undefined reference to iconv_open' /cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:54: undefined reference toiconv_open’
…/tools/win-sdk/lib\libSDL2.a(SDL_iconv.o): In function SDL_iconv_close_REAL': /cygdrive/e/openbor/SDL-2.0.8-12001/src/stdlib/SDL_iconv.c:60: undefined reference toiconv_close’
…/tools/win-sdk/lib\libSDL2.a(SDL_string.o): In function vsscanf': /usr/i686-w64-mingw32/sys-root/mingw/include/stdio.h:420: undefined reference to__ms_vsscanf’
…/tools/win-sdk/lib\libSDL2.a(SDL_string.o): In function vsnprintf': /usr/i686-w64-mingw32/sys-root/mingw/include/stdio.h:560: undefined reference to__ms_vsnprintf’
…/tools/win-sdk/lib\libSDL2.a(SDL_string.o): In function vsscanf': /usr/i686-w64-mingw32/sys-root/mingw/include/stdio.h:420: undefined reference to__ms_vsscanf’
…/tools/win-sdk/lib\libSDL2.a(SDL_string.o): In function vsnprintf': /usr/i686-w64-mingw32/sys-root/mingw/include/stdio.h:560: undefined reference to__ms_vsnprintf’
collect2.exe: error: ld returned 1 exit status
…\tools\bin\make.exe: *** [OpenBOR.elf] Error 1


#4

I tried to compile with MSYS and mingw-w64.
I obtain libSDL2.a etc…
-But when I compile my project with mingw32, during linking I got errors like:
mingw/include/stdio.h:420: undefined reference to__ms_vsscanf’…
-I have no error if I use the SAME compiler fro SDL and my project.

But I need to use my mingw32.
-For a strange reason when I compile with mingw32 libSDL2.a compiles ok, linking ok, bug during a game I got BAD audio and random crash.

I use:
./configure
make
make install

In the official SDL website you can see SDL2-devel-2.0.8-mingw.tar.gz but this is not updated to latest mercurial version BUT static libSDL2.a works in EVERY compiler!!
How can I compile libSDL2.a to work in every compiler?
Thanks…


#5

It seems like you have not set your linking folder to where libSDL2.dll.a is. But if you are trying to compile SDL statically, I don’t know. Maybe you need to do tricks with -Wl,-Bstatic and -Wl,-Bdynamic switches.

This is pretty much from the first link on google.


#6

Yes I set it. If I use libSDL2.a from official site it’s OK. If I use my own own compile version I get these reference errors… How you compile static lib?


#7

Looks like you aren’t linking SDL to the proper libraries for use with the static build. These should work, and since you’re using MinGW, order is important:

mingw32
libSDL2main.a
libSDL2.a
user32
gdi32
winmm
imm32
winspool
shell32
ole32
oleaut32
version
uuid
comdlg32
advapi32