Cross-compiling SDL from linux to windows (mingw/make)
by Linus Probert
So, I struggled a lot with this lately but finally got a standalone
executable that runs on windows with all the libraries included with
my game.
First of all comes the install of the mingw compiler libs. I’m on an
archlinux system. If you aren’t you will have to adapt to your own distro
but I don’t think that should be too hard. I might have forgotten some
of the libs that I actually needed but it’s not really relevant to the
post. You’ll have to adapt to your own project.
I could get all of these in one nice command (Archlinux):
The Makefile
Below will follow snippets of the Makefile that I produced. I named it
‘Makefile.win’ and it lives right next to my regular Makefile.
First set the variables and compiler flag. I set the compiler ‘CXX’
to mingw using absolute path. I also produce the correct flags based
on the libraries that I just installed. I hope this isn’t too hard to
follow if you have some knowledge of Make.
After that we tell make how to create object files from cpp files. Note that I named my mingw objectfiles .o32 in order to separate them from my regular build process. I highly recommend this.
That is more or less it for the actual build process. Once you get your
executable to compile it’s time to test it. Copy all the dll’s that your
program needs into the same folder as your executable (I added this to my
Makefile). On my system they were located in ‘/usr/x86_64-w64-mingw32/bin’
and they shared the name ‘almost’ with the libraries you included
during compile.
Testing
Once you have your executable and all the needed dlls in the same
folder it’s time to test. This is where wine will become very useful. I
initally tested my .exe on windows. Windows then told me what main dlls
that were missing if any, however, windows did not tell me what dlls
needed by included dlls that were missing. It would just fail to start
the program and I had no clue what was going wrong. When I got around
to testing my .exe in wine, wine would actually tell me exactly what
dlls were missing and what they were needed for. This helped ALOT.
Once you get your program to run on wine it should be pretty safe to
assume that it will run on actual windows as well.
I hope this helps people because getting this to work was a big hurdle
in my development process and I personally thought that there was little
information to find via google.
I’ll include my actual Makefile.win below. Note that this also builds a
library that I built and copys around a bunch of files so it might not
be as easy to read. I still want to include it though, for completeness
and in case I missed something in the sections above.