Wednesday, October 27, 2010

Porting Windstille to Windows via MinGW cross compiler

Once done with porting Windstille over to MacOSX I switched to porting it over to Windows:
  • Windows doesn't seem to have a clear MacPort alternative, so I went with compiling most libraries myself
  • SDL comes in precompiled binary form that is usable with MinGW
  • C++ libraries are incompatible between MinGW and Microsoft Visual C++, C libraries are often compatible, but not always, so building things yourself or downloading the MinGW specific binaries might be required
  • as the whole Windows FOSS landscape ended up looking a little to confusing for my taste, I switched over from native Windows to cross compiling from Linux, which also allowed me to use Linux tools in the build process and not having to worry about building them for Windows
  • Ubuntu comes with a ready to use cross compiler in the package gcc-mingw32
  • cross compiling standard autotools packages works with:
    ./configure --prefix=/home/ingo/projects/mingw32/run/ --host=i586-mingw32msvc --build=i686-linux-gnu
  • GLEW binaries didn't work and GLEW doesn't support cross compiling, using the Makefile.mingw and changing the compiler, linker, etc. names in it manually (g++ -> i586-mingw32msvc-c++) however did work
  • boost cross compile is a bit tricky, but well documented, make sure you only build the boost libraries you need, not everything, as that will cut down the build time from a few hours to a few minutes
  • Freetype, Ogg, JPEG and Vorbis compile smoothly
  • libpng and the required zlib do not cross compile smoothly, hacking the build scripts and hardcoding the compiler, linker, etc. names again did the trick
  • Gtk+ comes in a binary distribution that is usable in MinGW, but as it contains hardcoded path names in its pkg-config files some changes are needed (adjust to your build location as needed):
    sed -i "s/c:\/devel\/target\/.*/\/home\/ingo\/projects\/mingw32\/run\/opt\/gtk
    /" *.pc
  • Gtkmm and GtkGLExt are not part of that binary distribution and have to be build manually
  • with the Gtk+ binaries building Gtkmm wasn't all that hard, just a bit labor intensive due to the many dependencies
  • GtkGLExt is the most problematic and so far I didn't manage to create a working version, as the last release is incompatible with current Gtk+ and the latest development version of GtkGLExt is incompatible with GtkGLExtmm, I managed to produce compilable results by changing the latest release to handle newer Gtk+ versions (just a few macro changes), but the resulting application, while runable was not usable as the OpenGL widget leaked into other GUI elements and redraw behavior was completly broken
  • DLLs have to be in the current path for Wine to find them (still searching for a proper workaround for that)
  • OpenGL libraries have again other names, here its -lopengl32, this same naming convention is also used for GLEW and OpenAL
  • the gcc that comes with MinGW seems to be a lot more picky about the order of static libraries then the Linux gcc, had to reorder the libraries in my SCons file to make things build and fix undefined references
  • Free Software solutions for building Windows installers are: Inno Setup, NSIS and WiX
  • NSIS has the nice advantage that it comes as a Ubuntu package and thus is well suited for a cross-compiling environment, its config file syntax however seems a bit ugly and seems to require a good bit of manual book keeping to make proper uninstall, it also doesn't support .msi install files, only old style .exe
Overall compiling in native Windows seems kind of a mess, as you end up grabbing software from many different places and can never really be sure that they all will work properly together. Setting up a cross compile environment on the other side was reasonably simple, just a lot of manual compiling required and a few hacks here and there to get some libraries through, Wine seems to help a good bit to make most configure checks, that might try to run a .exe, work without hacks. Basic Gtk+ seems to be simpler to get up and running then on MacOSX, as it comes in a nice binary distribution with all the required libraries, lack of a working GtkGLExtmm however prevented the Windstille Editor from being usable.


Mathnerd314 said...

Compiling on windows is indeed a mess; I guess you stopped looking for precompiled binaries?

Grumbel said...

The biggest issue I had was simply that there didn't seem to be something as complete as Fink or MacPorts on Windows, so browsing around dozens of sites for packages got a little tiresome. But I didn't really look very hard so I might have missed something. MingwPort seems to be what I am looking for, but seems to be pretty much dead.

Anyway, cross-compiling worked fine for me and with Wine its easy to test stuff without dualbooting, so I am pretty happy with that.