SDL_mixer's playwave.exe linking error with SDL 1.2.15 on mingw32

among many other software projects SDL_mixer has
problems on mingw with latest SDL

SDL 1.2.14, SDL_mixer 1.2.12, Works fine:

/bin/sh ./libtool --mode=link gcc -o build/playwave.exe build/playwave.lo -I/min
gw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -L/mingw/lib -lmingw32 -lSDLmain
-lSDL -mwindows build/libSDL_mixer.la
libtool: link: gcc -o build/.libs/playwave.exe build/.libs/playwave.o -I/mingw/i
nclude/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -mwindows -L/mingw/lib build/.libs/l
ibSDL_mixer.dll.a -lmingw32 -lSDLmain /mingw/lib/libSDL.dll.a -luser32 -lgdi32 -
ldxguid -lwinmm /mingw/lib/libvorbisfile.dll.a /mingw/lib/libvorbis.dll.a /mingw
/lib/libogg.dll.a -L/mingw/lib

////////////////////////////////////////////////////////////////////////////////

SDL 1.2.15, SDL_mixer 1.2.12, doesnt work

/bin/sh ./libtool --mode=link gcc -o build/playwave.exe build/playwave.lo -I/min
gw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -L/mingw/lib -lmingw32 -lSDLmain
-lSDL -mwindows build/libSDL_mixer.la
libtool: link: gcc -o build/.libs/playwave.exe build/.libs/playwave.o -I/mingw/i
nclude/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -mwindows -L/mingw/lib /mingw/lib/li
bSDLmain.a build/.libs/libSDL_mixer.dll.a -lmingw32 /mingw/lib/libSDL.dll.a -lus
er32 -lgdi32 -ldxguid -lwinmm /mingw/lib/libvorbisfile.dll.a /mingw/lib/libvorbi
s.dll.a /mingw/lib/libogg.dll.a -L/mingw/lib
c:/q2wdevenv/lib/libmingw32.a(main.o): In function main': C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference toWinMai
n at 16’
collect2: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

////////////////////////////////////////////////////////////////////////

problem seems to be a messed up linking order.
other than the SDL version the environment is the same

env is latest official mingw installed via mingw-get

other projects using libsdl and sdl_mixer failing to build in a similar fashion

Looks like the GCC link like is missing “-mconsole”. That might get it to
work, but if it does, it is still somewhat of a hack.

PatrickOn Mon, Jan 23, 2012 at 1:10 PM, Marcel Wysocki wrote:

among many other software projects SDL_mixer has
problems on mingw with latest SDL

SDL 1.2.14, SDL_mixer 1.2.12, Works fine:

/bin/sh ./libtool --mode=link gcc -o build/playwave.exe build/playwave.lo
-I/min
gw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -L/mingw/lib -lmingw32
-lSDLmain
-lSDL -mwindows build/libSDL_mixer.la
libtool: link: gcc -o build/.libs/playwave.exe build/.libs/playwave.o
-I/mingw/i
nclude/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -mwindows -L/mingw/lib
build/.libs/l
ibSDL_mixer.dll.a -lmingw32 -lSDLmain /mingw/lib/libSDL.dll.a -luser32
-lgdi32 -
ldxguid -lwinmm /mingw/lib/libvorbisfile.dll.a /mingw/lib/libvorbis.dll.a
/mingw
/lib/libogg.dll.a -L/mingw/lib

////////////////////////////////////////////////////////////
////////////////////

SDL 1.2.15, SDL_mixer 1.2.12, doesnt work

/bin/sh ./libtool --mode=link gcc -o build/playwave.exe build/playwave.lo
-I/min
gw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -L/mingw/lib -lmingw32
-lSDLmain
-lSDL -mwindows build/libSDL_mixer.la
libtool: link: gcc -o build/.libs/playwave.exe build/.libs/playwave.o
-I/mingw/i
nclude/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -mwindows -L/mingw/lib
/mingw/lib/li
bSDLmain.a build/.libs/libSDL_mixer.dll.a -lmingw32
/mingw/lib/libSDL.dll.a -lus
er32 -lgdi32 -ldxguid -lwinmm /mingw/lib/libvorbisfile.dll.a
/mingw/lib/libvorbi
s.dll.a /mingw/lib/libogg.dll.a -L/mingw/lib
c:/q2wdevenv/lib/libmingw32.a(**main.o): In function main': C:\MinGW\msys\1.0\src\mingwrt/**../mingw/main.c:73: undefined reference toWinMai
n at 16’
collect2: ld returned 1 exit status
make: *** [build/playwave.exe] Error 1

////////////////////////////////////////////////////////////
////////////

problem seems to be a messed up linking order.
other than the SDL version the environment is the same

env is latest official mingw installed via mingw-get

other projects using libsdl and sdl_mixer failing to build in a similar
fashion

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

There was no -mconsole in 1.2.14 either and it worked just fine.
So that cant be the problem.On 01/24/2012 03:13 AM, Patrick Baggett wrote:

Looks like the GCC link like is missing “-mconsole”. That might get it
to work, but if it does, it is still somewhat of a hack.

OK, closer examination of the issue.

The problem is that on Win32 there are two main()'s:

console apps: main()
GUI apps: WinMain()

SDLmain.lib (I believe it is – src/main/win32/SDL_main_win32.c) contains
both. It calls SDL_main(), which is the app’s real function. I don’t know
why mingw is also providing a definition of main() that calls WinMain(). Is
"-lmingw32" really needed? It comes before “-lSDLmain”, so it would satify
a dependency first. Either way, I use MinGW and I certainly don’t have to
explicitly add any libmingw32.a to the link line…that seems like an
interesting artifact of libtool, perhaps.

PatrickOn Mon, Jan 23, 2012 at 1:17 PM, Marcel Wysocki wrote:

On 01/24/2012 03:13 AM, Patrick Baggett wrote:

Looks like the GCC link like is missing “-mconsole”. That might get it to
work, but if it does, it is still somewhat of a hack.

There was no -mconsole in 1.2.14 either and it worked just fine.
So that cant be the problem.

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

OK, closer examination of the issue.

The problem is that on Win32 there are two main()'s:

console apps: main()
GUI apps: WinMain()

SDLmain.lib (I believe it is –
src/main/win32/SDL_main_win32.c) contains both. It calls SDL_main(),
which is the app’s real function. I don’t know why mingw is also
providing a definition of main() that calls WinMain(). Is "-lmingw32"
really needed? It comes before “-lSDLmain”, so it would satify a
dependency first. Either way, I use MinGW and I certainly don’t have
to explicitly add any libmingw32.a to the link line…that seems like
an interesting artifact of libtool, perhaps.

libmingw32.a has been added automatically by whatever. and it is needed
IIRC.
but the linking oder should always be -lmingw32 -lSDLmain -lSDL
otherwise you just get the WinMain at 16 crap. even the SDL wiki says so.
http://wiki.libsdl.org/moin.cgi/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22
so i guess something in 1.2.15 has been changed that messes up this order.On 01/24/2012 03:28 AM, Patrick Baggett wrote:

Patrick

On Mon, Jan 23, 2012 at 1:17 PM, Marcel Wysocki <@Marcel_Wysocki mailto:Marcel_Wysocki> wrote:

On 01/24/2012 03:13 AM, Patrick Baggett wrote:

    Looks like the GCC link like is missing "-mconsole". That
    might get it to work, but if it does, it is still somewhat of
    a hack.

There was no -mconsole in 1.2.14 either and it worked just fine.
So that cant be the problem.

_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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

OK, closer examination of the issue.

The problem is that on Win32 there are two main()'s:

console apps: main()
GUI apps: WinMain()

SDLmain.lib (I believe it is –
src/main/win32/SDL_main_win32.c) contains both. It calls SDL_main(), which
is the app’s real function. I don’t know why mingw is also providing a
definition of main() that calls WinMain(). Is “-lmingw32” really needed?
It comes before “-lSDLmain”, so it would satify a dependency first. Either
way, I use MinGW and I certainly don’t have to explicitly add any
libmingw32.a to the link line…that seems like an interesting artifact of
libtool, perhaps.

libmingw32.a has been added automatically by whatever. and it is needed
IIRC.
but the linking oder should always be -lmingw32 -lSDLmain -lSDL
otherwise you just get the WinMain at 16 crap. even the SDL wiki says so.

http://wiki.libsdl.org/moin.cgi/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22
so i guess something in 1.2.15 has been changed that messes up this order.

What symbols are defined in libSDLmain.a (e.g. ‘nm libSDLmain.a’ )On Mon, Jan 23, 2012 at 1:32 PM, Marcel Wysocki wrote:

On 01/24/2012 03:28 AM, Patrick Baggett wrote:

Patrick

On Mon, Jan 23, 2012 at 1:17 PM, Marcel Wysocki wrote:

On 01/24/2012 03:13 AM, Patrick Baggett wrote:

Looks like the GCC link like is missing “-mconsole”. That might get it
to work, but if it does, it is still somewhat of a hack.

There was no -mconsole in 1.2.14 either and it worked just fine.
So that cant be the problem.


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


SDL mailing listSDL at lists.libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


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

This is 1.2.15:
$ nm /mingw/lib/libSDLmain.a

SDL_win32_main.o:
00000000 b .bss
00000000 d .data
00000000 N .debug_abbrev
00000000 N .debug_aranges
00000000 N .debug_info
00000000 N .debug_line
00000000 N .debug_loc
00000000 N .debug_ranges
00000000 N .debug_str
00000000 r .eh_frame
00000000 r .rdata
00000000 t .text
U _FreeLibrary at 4
U _GetCommandLineA at 0
U _GetModuleFileNameA at 12
U _GetModuleHandleA at 4
U _LoadLibraryA at 4
000001bc t _OutOfMemory
000001f0 t _ParseCommandLine
U _SDL_GetError
U _SDL_Init
U _SDL_Quit
U _SDL_SetModuleHandle
U _SDL_getenv
U _SDL_main
U _SDL_strlcat
U _SDL_strlcpy
00000610 T _WinMain at 16
U ___mingw_vfprintf
U __imp____mb_cur_max
U __imp___iob
U __imp___pctype
U __isctype
U _atexit
U _atoi
00000400 t _cleanup
00000408 t _cleanup_output
000004cc T _console_main
U _exit
U _fclose
U _fgetc
U _fopen
00000198 t _fprintf
U _freopen
U _malloc
00000000 t _redirect_output
U _remove
U _setbuf
U _setvbuf
00000140 b _stderrPath
00000000 b _stdioRedirectEnabled
00000020 b _stdoutPath
U _strrchr

and here 1.2.14:

SDL_win32_main.o:
00000000 b .bss
00000000 d .data
00000000 N .debug_abbrev
00000000 N .debug_aranges
00000000 N .debug_info
00000000 N .debug_line
00000000 N .debug_loc
00000000 N .debug_ranges
00000000 N .debug_str
00000000 r .eh_frame
00000000 r .rdata
00000000 t .text
U _FreeLibrary at 4
U _GetCommandLineA at 0
U _GetModuleFileNameA at 12
U _GetModuleHandleA at 4
U _LoadLibraryA at 4
000001bc t _OutOfMemory
000001f0 t _ParseCommandLine
U _SDL_GetError
U _SDL_Init
U _SDL_Quit
U _SDL_SetModuleHandle
U _SDL_getenv
U _SDL_main
U _SDL_strlcat
U _SDL_strlcpy
0000060c T _WinMain at 16
U ___mingw_vfprintf
U __imp____mb_cur_max
U __imp___iob
U __imp___pctype
U __isctype
U _atexit
U _atoi
000003fc t _cleanup
00000404 t _cleanup_output
000004c8 T _console_main
U _exit
U _fclose
U _fgetc
U _fopen
00000198 t _fprintf
U _freopen
U _malloc
00000000 t _redirect_output
U _remove
U _setbuf
U _setvbuf
00000140 b _stderrPath
00000000 b _stdioRedirectEnabled
00000020 b _stdoutPath
U _strrchrOn 01/24/2012 03:44 AM, Patrick Baggett wrote:

What symbols are defined in libSDLmain.a (e.g. ‘nm libSDLmain.a’ )

Doh, I was reading the 1.2.14 command line. Sorry, here’s the deal:

libmingw32.a -> provides main(), needs WinMain at 16
libSDLmain.a -> provides WinMain at 16, needs SDL_main()
yourapp.o -> provides SDL_main()

1.2.14 link line:
gcc -o build/.libs/playwave.exe build/.libs/playwave.o -I/mingw/i
nclude/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -mwindows -L/mingw/lib
build/.libs/l
ibSDL_mixer.dll.a* -lmingw32 -lSDLmain */mingw/lib/libSDL.dll.a -luser32
-lgdi32 -
ldxguid -lwinmm /mingw/lib/libvorbisfile.dll.a /mingw/lib/libvorbis.dll.a
/mingw
/lib/libogg.dll.a -L/mingw/lib

1.2.15 link line:
gcc -o build/.libs/playwave.exe build/.libs/playwave.o -I/mingw/i
nclude/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -mwindows -L/mingw/lib*/mingw/lib/li**
*bSDLmain.a build/.libs/libSDL_mixer.dll.a
-lmingw32/mingw/lib/libSDL.dll.a -lus
er32 -lgdi32 -ldxguid -lwinmm /mingw/lib/libvorbisfile.dll.a
/mingw/lib/libvorbi
s.dll.a /mingw/lib/libogg.dll.a -L/mingw/lib

It looks like the order got screwed up, though the libtool part looks OK:

/bin/sh ./libtool --mode=link gcc -o build/playwave.exe build/playwave.lo
-I/min
gw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -L/mingw/lib -lmingw32
-lSDLmain
*
*-lSDL -mwindows build/libSDL_mixer.la

I guess I’d start looking into the differences between .14 and .15’s
pkgconfig stuff.

On Mon, Jan 23, 2012 at 1:51 PM, Marcel Wysocki wrote:

On 01/24/2012 03:44 AM, Patrick Baggett wrote:

What symbols are defined in libSDLmain.a (e.g. ‘nm libSDLmain.a’ )

This is 1.2.15:
$ nm /mingw/lib/libSDLmain.a

SDL_win32_main.o:
00000000 b .bss
00000000 d .data
00000000 N .debug_abbrev
00000000 N .debug_aranges
00000000 N .debug_info
00000000 N .debug_line
00000000 N .debug_loc
00000000 N .debug_ranges
00000000 N .debug_str
00000000 r .eh_frame
00000000 r .rdata
00000000 t .text
U _FreeLibrary at 4
U _GetCommandLineA at 0
U _GetModuleFileNameA at 12
U _GetModuleHandleA at 4
U _LoadLibraryA at 4
000001bc t _OutOfMemory
000001f0 t _ParseCommandLine
U _SDL_GetError
U _SDL_Init
U _SDL_Quit
U _SDL_SetModuleHandle
U _SDL_getenv
U _SDL_main
U _SDL_strlcat
U _SDL_strlcpy
00000610 T _WinMain at 16
U ___mingw_vfprintf
U __imp____mb_cur_max
U __imp___iob
U __imp___pctype
U __isctype
U _atexit
U _atoi
00000400 t _cleanup
00000408 t _cleanup_output
000004cc T _console_main
U _exit
U _fclose
U _fgetc
U _fopen
00000198 t _fprintf
U _freopen
U _malloc
00000000 t _redirect_output
U _remove
U _setbuf
U _setvbuf
00000140 b _stderrPath
00000000 b _stdioRedirectEnabled
00000020 b _stdoutPath
U _strrchr

and here 1.2.14:

SDL_win32_main.o:
00000000 b .bss
00000000 d .data
00000000 N .debug_abbrev
00000000 N .debug_aranges
00000000 N .debug_info
00000000 N .debug_line
00000000 N .debug_loc
00000000 N .debug_ranges
00000000 N .debug_str
00000000 r .eh_frame
00000000 r .rdata
00000000 t .text
U _FreeLibrary at 4
U _GetCommandLineA at 0
U _GetModuleFileNameA at 12
U _GetModuleHandleA at 4
U _LoadLibraryA at 4
000001bc t _OutOfMemory
000001f0 t _ParseCommandLine
U _SDL_GetError
U _SDL_Init
U _SDL_Quit
U _SDL_SetModuleHandle
U _SDL_getenv
U _SDL_main
U _SDL_strlcat
U _SDL_strlcpy
0000060c T _WinMain at 16
U ___mingw_vfprintf
U __imp____mb_cur_max
U __imp___iob
U __imp___pctype
U __isctype
U _atexit
U _atoi
000003fc t _cleanup
00000404 t _cleanup_output
000004c8 T _console_main
U _exit
U _fclose
U _fgetc
U _fopen
00000198 t _fprintf
U _freopen
U _malloc
00000000 t _redirect_output
U _remove
U _setbuf
U _setvbuf
00000140 b _stderrPath
00000000 b _stdioRedirectEnabled
00000020 b _stdoutPath
U _strrchr

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

Ok whats new is the libSDLmain.la which did not exist in .14 but exists
in .15
But those files look fine.
I get the software to build by modifying libSDL_mixer.la
if i add /mingw/lib/libSDLmain.la to the dependency list there it
compiles fine.
i also removed -lmingw32 from there bcs according to the mingw people
you should never have to manually link against that.
although i dont know if this is the proper way. but it works.

suggestions anyone ?On 01/24/2012 04:09 AM, Patrick Baggett wrote:

I guess I’d start looking into the differences between .14 and .15’s
pkgconfig stuff.

another funny thing.
if i just move the /lib/mingw/libSDLmain.la away it compiles and links fine.
so works just as if i was using .14
i can use that as a temporary fix now. but i guess that someone more skilled
with libtool/pkgconfig/auto* should look into that.On 01/24/2012 02:27 PM, Marcel Wysocki wrote:

On 01/24/2012 04:09 AM, Patrick Baggett wrote:

I guess I’d start looking into the differences between .14 and .15’s
pkgconfig stuff.

Ok whats new is the libSDLmain.la which did not exist in .14 but
exists in .15
But those files look fine.
I get the software to build by modifying libSDL_mixer.la
if i add /mingw/lib/libSDLmain.la to the dependency list there it
compiles fine.
i also removed -lmingw32 from there bcs according to the mingw people
you should never have to manually link against that.
although i dont know if this is the proper way. but it works.

suggestions anyone ?