Cross compiling under Linux for Windows

I suppose that you want to do cross compiling because you are writing a cross-platform application. Under Linux you are probably using GCC and under Windows MinGW (Cygwin GCC may work too but I haven't tried that).


Installing MinGW under Debian is really easy as there is a binary package.
Just "apt-get install mingw32" (as root).
On my Debian unstable it installs itself as i586-mingw32msvc-* eg. i586-mingw32msvc-gcc for the gcc compiler.
On my machine it's located under /usr/i586-mingw32msvc/ this will be important later on. (binaries under /usr/bin/)

Change you build-system to use i586-mingw32msvc-(what ever) as the compiler.
You naturally also need to have all the libraries installed needed to compile under Windows installed on you Linux box. See below for examples.

If you are using you may take a look at my SDL Menu library, it's is configured for cross compiling (use option -cross when invoking


MinGW comes with OpenGL headers and lib files so you should be just fine.


Go to libSDL's homepage and download the development library for Windows (MinGW32 version).

Unpack it somewhere
Copy bin/i386-mingw32msvc-sdl-config to /usr/i586-mingw32msvc/bin/
Copy include/SDL to /usr/i586-mingw32msvc/include
Copy lib/libSDL* to /usr/i586-mingw32msvc/lib/

When invoking sdl-config use "/usr/i586-mingw32msvc/bin/i386-mingw32msvc-sdl-config --prefix=/usr/i586-mingw32msvc"

Again my menu library uses SDL and OpenGL.


Go to the SDL_image homepage and download (I know its for VisualStudio 6 but never mind that)

Copy include/SDL_image.h to /usr/i586-mingw32msvc/include
Copy lib/jpeg.dll lib/libpng1.dll lib/SDL_image.dll and lib/zlib.dll to /usr/i586-mingw32msvc/lib/
When using SDL_image just link with SDL_image (-lSDL_image). This is kinda magic but gcc can link with dll's


wxWidgets homepage.
cd to somewhere appropriate.
Get wxAll-2.5.3.tar.bz2 and wxWidgets-2.5.3-Patch02.tar.gz
unpack wxAll-2.5.3.tar.bz2 (tar -xvjf wxAll-2.5.3.tar.bz2)
cd wxWidgets-2.5.3
unpack wxWidgets-2.5.3-Patch02.tar.gz (tar -xvzf ../wxWidgets-2.5.3-Patch02.tar.gz)

Now you are ready to compile wxWidgets, I use Unicode for my applications as it makes foreign languages less problematic, I also like to statically link wxWidgets into my applications as wxWidgets can be compiled with so many different options.
Lets start with a Linux version
mkdir linux
cd linux
../configure --with-opengl --enable-gtk2 --with-gtk --enable-unicode --disable-shared
make install (as root)
If nothing went wrong you should have a wx-config command and should be capable of compiling applications using wxWidgets.
If something did go wrong chances are that you are missing some development versions of some libraries, libgtk2.0-dev for instance. Look at the output it will tell you what went wrong.

I order to create Unicode aware applications that can run under Windows 95/98 you need to have libunicows installed when "../configure" is run. You can get it here:
Get the version for MinGW unpack it and copy libunicows.a to /usr/i586-mingw32msvc/lib./

Now make sure that the mingw versions of gcc can be found as mingw32-*
On my machine I missed a lot of links so I created them using the excellent mmv program:
mmv -s "/usr/bin/i586-mingw32msvc-*" "/usr/bin/mingw32-#1"
Now you should be ready to configure and compile wxWidgets

When standing in the wxWidgets source directory:
mkdir windows
cd windows
../configure --host=mingw32 --prefix=/usr/i586-mingw32msvc --with-opengl --enable-unicode --disable-shared
make install

When cross compiling use /usr/i586-mingw32msvc/bin/wx-config instead of wx-config and you should be fine.

Note: I used wxWidgets 2.6.1 when trying this, also I still have to actually test the combination of Unicode and Win98.


You may even test your Windows executable using Wine the Windows emulator, this is't the most accurate test but it sure as hell is wicked, after all you app runs natively under Linux.
Tested using SDL and OpenGL.