Setting Up a Cross-platform Game Development Environment


GCC and MinGW

GCC is the GNU Compiler Collection and it is actually a suite of compilers that supports many languages, including Fortran, Ada, Java, Objective-C, C, and C++. There is also unofficial support for several other languages. We, of course, will be most interested in C++ and possibly C. The Wikipedia article has a nice brief overview of it.

Note that while the whole suite is collectively referred to as “GCC” one of the individual programs is also named “gcc”. That one is the C compiler, while the C++ compiler program is named “g++”. If you are manually compiling some C++ file it is easy to accidently type “gcc myfile.cpp” which will dutifully try – and fail – to compile your C++ file using the plain C compiler.

If you are running a Linux based OS, such as Ubuntu, Fedora, or like me you have Slackware, then you may already have gcc installed, but many Linux distributions no longer install a full suite of development tools by default, so it is best to install things yourself to be sure you have what you need.

Installation:

Fedora

You need lots of packages to make this work, so you might as well start out by installing a complete package group. From the command line as root

$ yum groupinstall "Development Tools"

After that you might also want to make sure you have the graphical interface to the gdb debugger installed.

$ yum install ddd

Ubuntu

On the current Ubuntu release – 10.04 – the gcc C compiler is preinstalled, but not the C++ compiler or most of the support tools you will need. From the command line, run

$ sudo apt-get install gcc g++ gcc-doc autoconf libtool gdb gdb-doc ddd cvs subversion git-core

gcc and g++ are the compiler, gdb and ddd the debugger, autoconf and libtool are build tools that may be needed by packages we want to install (SDL for example), and git, cvs, and subversion are source code revision control programs that may be handy if you need to download the source to a library (SDL uses subversion).

Windows

Microsoft operating systems are rather well known for providing only a very limited amount of software. The last time they shipped a programming language as a standard component it was a Basic interpreter with MS-DOS, so you will need to download and install a compiler yourself, and it turns out that there is more than one GCC port to choose from.

The two main ports of GCC for Windows are the one provided with Cygwin and the MinGW port.

Cygwin is a complete Posix development environment that includes a great deal more than just the compiler. It actually lets you compile standard Unix and Linux applications natively on Windows, including X-Windows applications. You can even build KDE and GNOME applications on Windows using Cygwin. This power is useful to some, but for us it is simply overkill.

That’s where MinGW – Minimalist GNU for Windows – comes in. It is a bare bones port of the GCC with a few required support tools, such as the GNU make program. The MinGW project also provides MSYS, which is a port of the Bash shell and many of the most useful Linux command line tools, and we will need the MSYS tools to help us build some of the support libraries we will be using.

Note: if you plan on using Code::Blocks you can install a version that comes with it’s own copy of MinGW in a fairly recent version that would be just fine. But you might still want to consider installing MinGW by hand. Doing so lets you get the latest version and also makes it easier to upgrade MinGW itself if it’s release schedule gets ahead of Code::Blocks. It’s your choice, though.

To install MinGW by hand, visit the Getting Started page. There you will find a link to the latest version of the graphical installer program, mingw-get-inst. Once you have it, just run it and follow the instructions, which mostly means clicking “Next” several times in a row.

Caution! The installer will ask you if you want to use pre-packaged repository catalogues or download the latest repository catalogues. Use the pre-packaged ones.

When I tested this and told it to download the latest catalogues, the installation failed. (The graphical installer is still in testing, which is why I didn’t link to it directly. There will likely be a more recent version by the time you read this.)

Accept the license aggreement (it’s the GPL, so there’s no “we own your immortal soul” provisions to worry about), and use the default installation location of C:\MinGW. When you get to choose the components to install, be sure to select the C++ Compiler and the MSYS Developer Toolkit because they aren’t selected by default!

The installer will download all of the components from the MinGW website and set everything up for you and you’ll be almost ready to go. You should update your command path. Right-click on the My Computer icon, select Properties, click on the Advanced tab, click the Environment Variables button, scroll down in the System variables list, double-click the Path variable, add “;C:\MinGW\bin” to the end of the value, click OK, OK, OK. Now the compiler will be runnable from the command line.

As a final note, if you use Code::Blocks and installed MinGW manually, be sure to go to “Settings->Compiler and Debugger Settings” in the Code::Blocks menu, select the “Toolchain Executables” tab of the dialog box, and make sure that MinGW has been detected. The Auto-detect button should find the compiler if it’s not already there.

2 Comments

  1. Wow, awesome timing. You’ve published this and your later article on CMake as I’m embarking on this very task. Thanks for the articles!

    • You’re welcome. I hope the information is useful. I’ve never written for others before, and I’m still learning this stuff myself, so I’m not sure if I’m really presenting things in a way that others can use. I’m trying, though.

      My next major post is probably going to be presenting a sample program that is a Mandelbrot set viewer. It’s not a game, of course, but it demonstrates using SDL. Benoit Mandelbrot died this past week, so I was inspired to create it in honor of his work.

Comments are closed.