Compilation with Mingw on Win32

I’m trying to compile the SDL test programs with the Mingw compiler by typing:

gcc testsprite.c -I[SDL_include_directory] -L[SDL_libs] -lsdl

but I get this error:

[…]libmingw32.a(main.o)(.text+0x8e): undefined reference to ‘WinMain at 16’

I’m using the 2.95.2 MSVCRT version. Do I need the CRTDLL version instead?

(Sorry if someone had answered this before)

Alberto

There is another library you have to include, the one that makes it so
that you are making a windows app instead of a console one, I just
can’t remember off the top of my head what lib that is. I think the
demo program that comes with mingw32 uses it though. Maybe some nice
person in this list will refresh my memory for you :slight_smile:

Alberto Luaces wrote:

I’m trying to compile the SDL test programs with the Mingw compiler by
typing:>
gcc testsprite.c -I[SDL_include_directory] -L[SDL_libs] -lsdl

but I get this error:

[…]libmingw32.a(main.o)(.text+0x8e): undefined reference to ‘WinMain at 16’

I’m using the 2.95.2 MSVCRT version. Do I need the CRTDLL version instead?

(Sorry if someone had answered this before)

Alberto

I had the same problem. The answer is in the sdl-config script
generated when you build the SDL lib for mingw32. When I run that
script with the --libs flag I get:
-L/usr/local/cross-tools/i386-mingw32msvc/lib -lmingw32 -lSDLmain -lSDL -luser32 -lgdi32 -lwinmm -ldxguid -mwindows

it’s one of those libs or the -mwindows. I don’t know which, but it
fixes the problem. If the program uses autoconf you just need to make
sure configure finds the right sdl-config. Hope this is what you need.

On the same subject, I have just been fighting SDL_image on mingw32. I
need it to work with PNG support. I downloaded the pre-compiled
version that is linked to from the SDL site (It’s at:
http://www.slothmud.org/~hayward/Xmingw32/), but it didn’t work. My
program compiles fine, but when it tries to link I get these errors:
<>
c++ -g -O2 -I/usr/local/cross-tools/i386-mingw32msvc/include -I/usr/local/cross-tools/i386-mingw32msvc/include/SDL -Dmain=SDL_main -o aak aak.o util.o video.o audio.o screen.o blitables.o -lSDL_mixer -lSDL_image -lpng -lz -L/usr/local/cross-tools/i386-mingw32msvc/lib -lmingw32 -lSDLmain -lSDL -luser32 -lgdi32 -lwinmm -ldxguid -mwindows
/usr/local/cross-tools/i386-mingw32msvc/lib/libpng.a(pngerror.o)(.text+0x21d):pngerror.c: undefined reference to __imp__iob' /usr/local/cross-tools/i386-mingw32msvc/lib/libpng.a(pngerror.o)(.text+0x261):pngerror.c: undefined reference to__imp__iob’
/usr/local/cross-tools/i386-mingw32msvc/lib/libpng.a(pngrutil.o)(.text+0xe1a):pngrutil.c: undefined reference to __imp__iob' /usr/local/cross-tools/i386-mingw32msvc/lib/libpng.a(pngrutil.o)(.text+0x1b1d):pngrutil.c: undefined reference to__imp__iob’
/usr/local/cross-tools/i386-mingw32msvc/lib/libpng.a(pngrutil.o)(.text+0x1b5d):pngrutil.c: undefined reference to __imp__iob' /usr/local/cross-tools/i386-mingw32msvc/lib/libpng.a(pngrutil.o)(.text+0x1f00):pngrutil.c: more undefined references to__imp__iob’ follow
<>

I have to edit the Makefile to add -lSDL_image -lpng, because these
same errors prevent ./configure from detecting them. I have not tried
recompiling libpng. I looked like it would be quite a job (no info in
the docs about mingw32 or any other cross-compiling stuff, and no
autoconf to help me). I thought someone might know what "__imp__iob"
is all about or what library it is in. Thanks in advance.

-Arthur Peters

Arthur Peters wrote:

On the same subject, I have just been fighting SDL_image on mingw32. I
need it to work with PNG support. I downloaded the pre-compiled
version that is linked to from the SDL site (It’s at:
http://www.slothmud.org/~hayward/Xmingw32/), but it didn’t work. My
program compiles fine, but when it tries to link I get these errors:

I have to edit the Makefile to add -lSDL_image -lpng, because these
same errors prevent ./configure from detecting them. I have not tried
recompiling libpng. I looked like it would be quite a job (no info in
the docs about mingw32 or any other cross-compiling stuff, and no
autoconf to help me). I thought someone might know what “__imp__iob”
is all about or what library it is in. Thanks in advance.

-Arthur Peters

I’ve submitted patches for SDL_image, SDL_ttf, and SDL_mixer to
make cross compiling go smoothly. I also have build scripts for
libpng, libjpeg, zlib, and freetype. I will try to post these
things on my web page tonight, since with LinuxWorld going on and
all, I doubt the updated versions will be release really soon :slight_smile:

Now the “Undefined reference to ‘WinMain at 16’” is gone by including all the
libraries you told me. But I still got a problem: The Mingw complains about
libsdlmain.a:

libsdlmain.a(SDLmain.o): In function ‘console_main’:
/home/hercules/public_cvs/SDL-1.1/src/main/SDL_main.c:136: undefined
reference to ‘SDL_RegisterApp’

I can’t run ./configure nor ./sdl-config because they need bash to get
executed, and I’m on W95. If this helps, I got SDL on this file:

SDL-devel-1.1.2-mingw32.tar.gz (maybe I got the wrong file)

Thaks,

Alberto

At 15:47 15/08/00 -0500, you wrote:

I had the same problem. The answer is in the sdl-config script
generated when you build the SDL lib for mingw32. When I run that
script with the --libs flag I get:
-L/usr/local/cross-tools/i386-mingw32msvc/lib -lmingw32 -lSDLmain -lSDL
-luser32 -lgdi32 -lwinmm -ldxguid -mwindows>
it’s one of those libs or the -mwindows. I don’t know which, but it
fixes the problem. If the program uses autoconf you just need to make
sure configure finds the right sdl-config. Hope this is what you need.

-Arthur Peters