# Compilation with Mingw on Win32

**URL:** <https://discourse.libsdl.org/t/compilation-with-mingw-on-win32/2986>\
**Category:** SDL Development\
**Created:** [August 14, 2000, 1:49pm UTC](https://discourse.libsdl.org/t/compilation-with-mingw-on-win32/2986 "2000-08-14T13:49:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alberto\_Luaces](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@Alberto\_Luaces](https://discourse.libsdl.org/u/Alberto_Luaces)\
**Post date:** [August 14, 2000, 1:49pm UTC](https://discourse.libsdl.org/t/compilation-with-mingw-on-win32/2986/1 "2000-08-14T13:49:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wes\_Poole](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/w/13edae/32.png) [@Wes\_Poole](https://discourse.libsdl.org/u/Wes_Poole)\
**Post date:** [August 15, 2000, 5:43pm UTC](https://discourse.libsdl.org/t/compilation-with-mingw-on-win32/2986/2 "2000-08-15T17:43:55Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![Arthur\_Peters](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@Arthur\_Peters](https://discourse.libsdl.org/u/Arthur_Peters)\
**Post date:** [August 15, 2000, 8:47pm UTC](https://discourse.libsdl.org/t/compilation-with-mingw-on-win32/2986/3 "2000-08-15T20:47:00Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![Ray\_Kelm](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/r/fbc32d/32.png) [@Ray\_Kelm](https://discourse.libsdl.org/u/Ray_Kelm)\
**Post date:** [August 15, 2000, 11:44pm UTC](https://discourse.libsdl.org/t/compilation-with-mingw-on-win32/2986/4 "2000-08-15T23:44:02Z")

</div>

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/](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 🙂

---

<div class="post-metadata">

**Author:** ![Alberto\_Luaces](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@Alberto\_Luaces](https://discourse.libsdl.org/u/Alberto_Luaces)\
**Post date:** [August 18, 2000, 3:51pm UTC](https://discourse.libsdl.org/t/compilation-with-mingw-on-win32/2986/5 "2000-08-18T15:51:15Z")

</div>

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
