l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2004 Aug 04 00:47

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Cross compiling SDL/OpenGL on Linux for a win32executable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Cross compiling SDL/OpenGL on Linux for a win32executable

Hi all,

I finally managed to cross compile an SDL/OpenGL program on Linux for
win32.  Here's how I did it and some pitfalls along the way.  This was
_not_ easy to figure out!  I hope other people can benefit from this.

This email is to be regarded as heuristic knowledge.  Some of it I had
no idea of the rhyme or reason.  It's just a lot of edumacated
guesswork, trial and error, Googling and good ol fasioned

Downloading Stuff

1a. Download and run the cross-compile tools installer from:


   Running this script will download almost everything I needed.  Among
   other things, it downloaded the cross compiler mingw32 and a
   binutils.  By default, it nicely puts everything in

1b. Download the SDL libraries:


   Install to the /usr/local/cross-tools tree with "make cross".

1c. Download the cross-make script from:


    and put it in the directory of your source code.

1d. If you know how to use auto-tools, download:


    and put it in the directory of your source code.

Coding Stuff

2a. main() must be defined as:

      int main( int argc, char *argv[] )

   and definitely not:

      int main( void )

   otherwise you'll get "previous declaration of `SDL_main'" errors
   (even if you don't use argc and argv).  If the "unused parameter"
   warnings bug you, use the -Wno-unused-parameter compiler flag.  In
   particular, don't define or declare:

      anything WinMain( anything )

   despite what the error/warning messages tell you.

2b. Never use the standard GL header files:

      #include <GL/gl.h>
      #include <GL/glu.h>

   Instead, use this one if you're going to use OpenGL:

      #include <SDL_opengl.h>

   I've been told this is a good habit to get into even if you have no
   immediate plans to cross compile.

Making Stuff

3a. Don't use "sdl-config --libs" for linking.  Instead, use this, and
   don't change the order; ORDER IS IMPORTANT:

      -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32

   If you get "-lpthread not found" errors, you've used sdl-config for
   the linking stage.

3b.  Note that instead of "-lGL", you use "-lopengl32".  Instead of
   "-lglu", you use "-lglu32".  If you're going to use GLUT for
   windowing, you use "-lglut32" instead of "-lglut".

3c. This is my first working cross compile Makefile (you need a
   directory .deps/ in the source directory):

   TARGET = alpha-blending.exe
   CFILES = $(wildcard *.c)
   OFILES = $(patsubst %.c, %.o, $(CFILES))
   DFILES = $(patsubst %.c, .deps/%.d, $(CFILES))
   CC     = gcc
   WARN   = -W -Wall -Wmissing-prototypes -Waggregate-return -Wpointer-arith \
            -Wcast-qual -Wcast-align -Wmissing-declarations -Wnested-externs \
            -Wredundant-decls -Wwrite-strings -Winline -Wno-unused-parameter
   CFLAGS = `sdl-config --cflags` $(WARN)
   LDLIBS = -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32

   all: $(TARGET)
      $(CC) -o $(TARGET) $(OFILES) $(LDLIBS)

   .deps/%.d: %.c
      @$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
      sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm $@.$$$$

   ifneq ($(MAKECMDGOALS),clean)
   -include $(DFILES)

   .PHONY: clean

      $(RM) $(TARGET) $(OFILES) $(DFILES) core

3d. To cross compile, you use:

      sh cross-make.sh

   Where cross-make.sh is one of the files you downloaded from step 1c.

3e. By default, things are linked dynamically, so wherever your
   application goes, the person will need a copy of SDL.dll (which comes
   with the stuff you downloaded in step 1).

   Mingw32 knows the -static switch, but I haven't tested it yet.

3f. My cross compiled win32 applications ran on MS Windows (yay!) but it
   crashed wine/winex.  YMMV.

7g. My makefile is cross-compile only.  I currently need two makefiles;
   one for Linux and another for cross compiling for win32.  This email:


   describes a portable Makefile (without autotools) and deserves to be
   looked at when I have more time.

I worked up a sweat figuring this one out!  Sheesh!


Make everything as simple as possible, but no simpler. -- Albert Einstein
GPG Instructions: http://www.dirac.org/linux/gpg
GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.