Cross compile SDL_mixer


#1

Hello,

I would like to cross compile SDL_mixer-1.2.12 with my cross compiler (binutils-2.22, gcc-4.7.1, w32api-3.17-2-mingw32 and mingwrt-3.20-2-mingw32).
I already cross compiled SDL, SDL_ttf and SDL_net with my cross compiler, so it should work with SDL_mixer.

I do this:
$ export PKG_CONFIG_PATH=/usr/i686-pc-mingw32/lib/pkgconfig
$ ./configure --prefix=/usr/i686-pc-mingw32 --host=i686-pc-mingw32 --with-smpeg-prefix=/usr/i686-pc-mingw32 --disable-music-mod
$ make
/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL build/libSDL_mixer.la
libtool: link: i686-pc-mingw32-gcc -o build/.libs/playwave.exe build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a /usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32 /usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm -L/usr/i686-pc-mingw32/lib
/usr/i686-pc-mingw32/lib/libmingw32.a(main.o): In function main': /home/yugiohjcj/documents/downloads/software/mingwrt-3.20-2-mingw32/main.c:73: undefined reference toWinMain at 16’
collect2: error: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

Can you explain me why I got this error ?

Thank you.
Regards.


#2

I think it’s a flaw in autotools. I think if you copy that link line out
and move the reference to SDLmain after -lmingw32 it’ll work.On Fri, Sep 21, 2012 at 9:16 AM, YuGiOhJCJ Mailing-List < yugiohjcj-mailinglist at laposte.net> wrote:

Hello,

I would like to cross compile SDL_mixer-1.2.12 with my cross compiler
(binutils-2.22, gcc-4.7.1, w32api-3.17-2-mingw32 and
mingwrt-3.20-2-mingw32).
I already cross compiled SDL, SDL_ttf and SDL_net with my cross compiler,
so it should work with SDL_mixer.

I do this:
$ export PKG_CONFIG_PATH=/usr/i686-pc-mingw32/lib/pkgconfig
$ ./configure --prefix=/usr/i686-pc-mingw32 --host=i686-pc-mingw32
–with-smpeg-prefix=/usr/i686-pc-mingw32 --disable-music-mod
$ make
/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe
build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main
-I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib
-lmingw32 -lSDLmain -lSDL build/libSDL_mixer.la
libtool: link: i686-pc-mingw32-gcc -o build/.libs/playwave.exe
build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main
-I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib
build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a
/usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32
/usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm
-L/usr/i686-pc-mingw32/lib
/usr/i686-pc-mingw32/lib/libmingw32.a(main.o): In function main': /home/yugiohjcj/documents/downloads/software/mingwrt-3.20-2-mingw32/main.c:73: undefined reference toWinMain at 16’
collect2: error: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

Can you explain me why I got this error ?

Thank you.
Regards.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


#3

But SDLmain seems already to respect this order, see here:
$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL

SDLmain is after -lmingw32, isn’t it?
So, why this error?On Sun, 23 Sep 2012 01:30:48 -0700 Sam Lantinga wrote:

I think it’s a flaw in autotools. I think if you copy that link line out
and move the reference to SDLmain after -lmingw32 it’ll work.

On Fri, Sep 21, 2012 at 9:16 AM, YuGiOhJCJ Mailing-List < @YuGiOhJCJ_Mailing-Li> wrote:

Hello,

I would like to cross compile SDL_mixer-1.2.12 with my cross compiler
(binutils-2.22, gcc-4.7.1, w32api-3.17-2-mingw32 and
mingwrt-3.20-2-mingw32).
I already cross compiled SDL, SDL_ttf and SDL_net with my cross compiler,
so it should work with SDL_mixer.

I do this:
$ export PKG_CONFIG_PATH=/usr/i686-pc-mingw32/lib/pkgconfig
$ ./configure --prefix=/usr/i686-pc-mingw32 --host=i686-pc-mingw32
–with-smpeg-prefix=/usr/i686-pc-mingw32 --disable-music-mod
$ make
/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe
build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main
-I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib
-lmingw32 -lSDLmain -lSDL build/libSDL_mixer.la
libtool: link: i686-pc-mingw32-gcc -o build/.libs/playwave.exe
build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main
-I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib
build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a
/usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32
/usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm
-L/usr/i686-pc-mingw32/lib
/usr/i686-pc-mingw32/lib/libmingw32.a(main.o): In function main': /home/yugiohjcj/documents/downloads/software/mingwrt-3.20-2-mingw32/main.c:73: undefined reference toWinMain at 16’
collect2: error: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

Can you explain me why I got this error ?

Thank you.
Regards.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


#4

2012/9/23 YuGiOhJCJ Mailing-List

But SDLmain seems already to respect this order, see here:
$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain
-lSDL -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg
-L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL

SDLmain is after -lmingw32, isn’t it?
So, why this error?

It needs to be the other way around, GCC has a “feature/bug” that solves
dependencies among libraries, so as SDLmain depends on mingw32, it needs to
come before (in a left to right order).
So, your line needs to be something like -lSDLmain -lSDL -lmingw32

Strangely, I cross compile SDL2 with Mingw32 from Ubuntu 12.04 and don’t
get this error.–
Gabriel.


#5

2012/9/23 YuGiOhJCJ Mailing-List <@YuGiOhJCJ_Mailing-Li>

But SDLmain seems already to respect this order, see here:
$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain
-lSDL -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg
-L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL

SDLmain is after -lmingw32, isn’t it?
So, why this error?

It needs to be the other way around, GCC has a “feature/bug” that solves
dependencies among libraries, so as SDLmain depends on mingw32, it needs to
come before (in a left to right order).
So, your line needs to be something like -lSDLmain -lSDL -lmingw32

Strangely, I cross compile SDL2 with Mingw32 from Ubuntu 12.04 and don’t
get this error.

I put SDLmain before mingw32:
$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL

But it doesn’t help:
$ make
/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL build/libSDL_mixer.la
libtool: link: i686-pc-mingw32-gcc -o build/.libs/playwave.exe build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a /usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32 /usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm -L/usr/i686-pc-mingw32/lib
/usr/i686-pc-mingw32/lib/libmingw32.a(main.o): In function main': /home/yugiohjcj/documents/downloads/software/mingwrt-3.20-2-mingw32/main.c:73: undefined reference toWinMain at 16’
collect2: error: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

Any other idea?On Sun, 23 Sep 2012 11:52:32 -0300 Gabriel Jacobo wrote:


#6

2012/9/23 YuGiOhJCJ Mailing-List <@YuGiOhJCJ_Mailing-Li>

But SDLmain seems already to respect this order, see here:
$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain
-lSDL -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg
-L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lmingw32 -lSDLmain -lSDL

SDLmain is after -lmingw32, isn’t it?
So, why this error?

It needs to be the other way around, GCC has a “feature/bug” that solves
dependencies among libraries, so as SDLmain depends on mingw32, it needs to
come before (in a left to right order).
So, your line needs to be something like -lSDLmain -lSDL -lmingw32

Strangely, I cross compile SDL2 with Mingw32 from Ubuntu 12.04 and don’t
get this error.

I put SDLmain before mingw32:
$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL

But it doesn’t help:
$ make
/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lmingw32 -lSDL build/libSDL_mixer.la
libtool: link: i686-pc-mingw32-gcc -o build/.libs/playwave.exe build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a /usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32 /usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm -L/usr/i686-pc-mingw32/lib
/usr/i686-pc-mingw32/lib/libmingw32.a(main.o): In function main': /home/yugiohjcj/documents/downloads/software/mingwrt-3.20-2-mingw32/main.c:73: undefined reference toWinMain at 16’
collect2: error: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

Any other idea?

I also try this order:
$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32 -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32 -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32
spierre at eeepc:~/documents/downloads/software/SDL_mixer-1.2.12$ cat Makefile | grep SDLmain
EXTRA_LDFLAGS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32 -lwinmm -L/usr/i686-pc-mingw32/lib -lsmpeg -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32 -mwindows -lm
SDL_LIBS = -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32

But it doesn’t help:
$ make
/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32 build/libSDL_mixer.la
libtool: link: i686-pc-mingw32-gcc -o build/.libs/playwave.exe build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a /usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32 /usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm -L/usr/i686-pc-mingw32/lib
/usr/i686-pc-mingw32/lib/libmingw32.a(main.o): In function main': /home/yugiohjcj/documents/downloads/software/mingwrt-3.20-2-mingw32/main.c:73: undefined reference toWinMain at 16’
collect2: error: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

Any other idea?On Sun, 23 Sep 2012 17:13:44 +0200 YuGiOhJCJ Mailing-List <@YuGiOhJCJ_Mailing-Li> wrote:

On Sun, 23 Sep 2012 11:52:32 -0300 Gabriel Jacobo wrote:

YuGiOhJCJ <@YuGiOhJCJ_Mailing-Li>
http://yugiohjcj.1s.fr/


#7

Sorry for digging out an old thread, but it may help someone.

But it doesn’t help:
$ make
/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32 build/libSDL_mixer.la
libtool: link: i686-pc-mingw32-gcc -o build/.libs/playwave.exe build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a /usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32 /usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm -L/usr/i686-pc-mingw32/lib
/usr/i686-pc-mingw32/lib/libmingw32.a(main.o): In function main': /home/yugiohjcj/documents/downloads/software/mingwrt-3.20-2-mingw32/main.c:73: undefined reference to WinMain at 16’
collect2: error: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

Any other idea?

Take a close look what libtool is doing, at first the command line parameters are correct:

/bin/sh ./libtool --mode=link i686-pc-mingw32-gcc -o build/playwave.exe build/playwave.lo -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib -lSDLmain -lSDL -lmingw32 build/libSDL_mixer.la

But when the linking is done the parameters “-lSDLmain -lSDL” are missing:

i686-pc-mingw32-gcc -o build/.libs/playwave.exe build/.libs/playwave.o -D_GNU_SOURCE=1 -Dmain=SDL_main -I/usr/i686-pc-mingw32/include/SDL -mwindows -L/usr/i686-pc-mingw32/lib build/.libs/libSDL_mixer.dll.a /usr/i686-pc-mingw32/lib/libSDLmain.a /usr/i686-pc-mingw32/lib/libstdc++.dll.a -lmingw32 /usr/i686-pc-mingw32/lib/libSDL.dll.a -luser32 -lgdi32 -lwinmm -L/usr/i686-pc-mingw32/lib

If you add them manually it will work, at least it did in my case. In order to do this you can edit libSDL.la and change the following line

dependency_libs=' -luser32 -lgdi32 -lwinmm -ldxguid'

…to…

dependency_libs=' -luser32 -lgdi32 -lwinmm -ldxguid -lSDLmain -lSDL'

#8

Wow thanks a lot it works!
I attach the patch to this email.

Best regards.

i686-w64-mingw32-sdl-mixer-1.2.12.patch (1.02 KB)

i686-w64-mingw32-sdl-mixer-1.2.12.patch (1.02 KB)


#9

Adding the missing flags by changing the Makefile.in is of course a far better solution, thank you!