I’m developing The Undergrounder entirely on Linux because that’s the best environment for my needs, but my code is mostly based on SDL and OpenGL, so compiling on other systems is not a problem.
Last week I decided to set up my Windows box to have a second build available for testers (the Mac OS X one will come soon).
There are several possible options for compiling SDL/OpenGL code on Windows, but my choice was to use MinGW (for compiler and libraries) and Cygwin (for bash, tools and python) so to have a Linux-like environment and minimize the changes in the sources and the building scripts.
In a perfect world the set-up should require 4 easy steps like:
- Install MinGW
- Install Cygwin
- Convert/compile the libraries
- Compile
But unfortunately all these tools are far from perfection, so I had to put some extra effort to get a working environment and an executable. I’m not saying these are bad tools and I still think the developers are doing a great job especially allowing people to have them for free, but I’m pretty sure most of the unexperienced developers would give up during the installation process if few minor issues are not addressed soon.
Anyway, I decided to write this blog post to keep track of all things I had to do and to share my experience with other developers. This post is not intended to be a comprehensive guide to building applications on Windows and your project could need different steps, but I hope this will help most of the people trying to compile code on Windows.
In order to compile my code I need the following libraries: GLEW (OpenGL), SDL, SDL_image, SDL ttf 2 and a construction tool called Scons (a way better than make and the autotools), so the following steps will describe how I managed to compile my game based on these libraries/tools.
1. You can install MinGW using the automated installer, but the installer is no longer maintained, so now the best way to install MinGW should be the manual installation described in their wiki.
2. The automated installer downloaded gcc 4.5.0 even if it was supposed to install the 4.4.0, but the compiler didn’t work so I had to install gcc 4.4.0 downloading the bin and dll packages of gcc-core and gcc-g++ and unpacking the archives in the directory where I installed MinGW (say C:\MinGW).
3. Then install Cygwin downloading the latest version of the installer from the website.
The installer works pretty well and allows you to decide which packages to install. The only packages I added to the default installation are: bash, python and Vim
4. Once installed Cygwin you need to run the shell and edit the PATH environment variable in /etc/profile adding “/cygdrive/c/MinGW:” at the beginning of the list of paths. This step is required to tell the Cygwin shell to use MinGW programs (like gcc).
5. This step was supposed to be converting .lib library files to .a so to allow the MinGW linker to use them.
This conversion is done using a program called reimp contained in the mingw-utils package.
Unfortunately the program contained in the latest version of the package (0.4.1) doesn’t work, so you have to download the sources
and build all the binaries from scratch.
6. In order to compile the programs contained in mingw-utils you need to install MSYS, the Minimal SYStem used to compile programs with MinGW. MSYS doesn’t have an installer, but you have to download and unpack all the needed packages in a directory (say C:\MSYS).
The basic packages required to compile programs are: base system, bash, binutils, coreutils, gawk, grep, m4, make.
More packages could be required for compiling different programs
7. Once installed all the MSYS packages, mount the MinGW directory to /mingw so to make installation of new programs (like mingw-utils) easier. All you need to do is launching the MSYS shell and type “mount C:/MinGW /mingw”
8. Now it’s possible to compile mingw-utils from the MSYS shell following the common procedure for building programs on Linux:
“./configure –prefix=/mingw ; make ; make install“
9. At last it’s possible to convert the SDL libraries, so download the devel-*-VC packages and convert the .lib files contained in the lib\ directory of each package using the command “reimp -c file.lib” from the Cygwin shell.
In order to install the libraries you need to copy the obtained .a files to C:\MinGW\lib\ and copy the include\SDL\ directory contained in the packages to C:\MinGW\include
10. The other library to convert is GLEW, a library used to load OpenGL extensions and use the latest OpenGL version allowed by your graphic drivers, but unfortunately converting the .lib file contained in the binary package is not enough for compiling OpenGL programs, so you have to download the source code and compile them using MYSYS (the Makefile raised some errors trying to compile with Cygwin).
Once compiled the library all you need to do is to copy the obtained .a files to C:\MinGW\lib and copy include\GL contained in the GLEW package to C:\MinGW\include
br />
11. The last component to download is scons-local that needs to be unpacked in the directory of the project to compile (the one containing the SConstruct).
Of course, If you use a different building tool, this and the following steps need to be adapted to your project.
12. The last step required before compiling is editing the SConstruct so to have the following lines:
env = Environment(tools=['mingw'])
env.Append(LIBS=['mingw32', 'SDLmain', 'SDL', 'SDL_image', 'SDL_ttf', 'glew32', 'glu32', 'opengl32'])
env['ENV']['PATH'] = ‘/cygdrive/c/MinGW/bin:’ + env['ENV']['PATH']
13. Finally it’s possible to compile the code using the Cygwin shell typing “python scons.py” in the project directory.
These steps are definitely more than 4, but at least I managed to have a working environment and compile our game, hope this post will help other people getting the same result.
If you need any help with your project don’t esitate to contact us commenting this post.