Ceniza's Website - MinGW

Back to Programming 



Before you start:

The following instructions will guide you in how to install Allegro with MinGW and also how to set up UnxUtils and Dev-C++ for it. It will soon include how to get it working with Code::Blocks too (I hope).

It is recommended that you get the latest versions of everything you'll need. If you have already got them you can jump to the Step by step section in this page (just scroll down a bit) and if you haven't, just continue reading.

Go to MinGW's file list in the download page and search for Current in the first column and, still in there, MinGW (the one that just says that 'cause you'll also find MinGW Runtime, MinGW Utilities, ...). Now just click the exe file to download it. In the next page choose any mirror and wait for it to download.

WARNING: At the writing of this guide the current version of MinGW's installer (version 4.1.1) is having problems. You can try to use it and check if it was successfully installed. If that isn't the case or you want to install it manually read this and ignore the step about "installing MinGW" in the Step by step section.

Good, now you've got the installer for the compiler. Just remember this installer is just a wizard to help you with the installation. When you have chosen what you want to get it'll need to download the packages and install them. More of it in the Step by step section.

There are currently two branches of Allegro: stable and WIP. You are free to download whichever you want. In our case we will work with the WIP version that can be downloaded from here. You should download the ZIP file which is ready for DOS and Windows.

UnxUtils is a package with a lot of *nix utilities that can be useful and that Allegro can use too. It can be downloaded from here.

Dev-C++ is an IDE that can be downloaded with MinGW included in it, even though I don't recommend such a choice due to a few problems it has had compiling C++ sources and also because the MinGW version that comes with it is really old. What you can do is just to download the editor and configure it to use the current MinGW installation. Just go here, scroll down to Downloads and download the one that says "executable only".

Another IDE really promising is Code::Blocks which you're free to try. You can get it from here.

Step by step:

The following steps suppose that you have downloaded all the files from the Before you start section. If you have not downloaded one of those files, just skip the step where it is named.

  • Install MinGW in the recommended folder (C:\MinGW). This guide will suppose you will install it in that folder. If you want or need to install it somewhere else, remember to change C:\MinGW by the folder you installed it in for all the further steps.

To do so execute the file you downloaded from MinGW's site. Follow all the instructions till you get to Select components. In there you're free to change from current version to candidate version. Candidate will give you the latest versions of everything, current will give you the most stable ones. Whatever you choose just click Next.

Now you'll be asked to Select Additional Tasks. For Allegro you'll just need mingw32-make, binutils, gcc-core and gcc-g++. You're free to get them all if you want but I'd suggest you to get just those. Click Next.

Now you're ready to install them, so click Install, wait for the packages to download and be installed.

  • Decompress Allegro somewhere in your hard disk. I'll assume you decompress it in C:\MinGW. It'll be decompressed in a folder named allegro, so all the sources will reside in C:\MinGW\allegro.
  • Decompress UnxUtils somewhere in your hard disk. I'll assume you decompress it in C:\unxutils. It will create some subfolders, where usr\local\wbin\ will have all the necessary utilities.
  • Decompress Dev-C++ somewhere in your hard disk. I'll assume you decompress it in C:\Dev-Cpp. IT IS HIGHTLY RECOMMENDED THAT YOU DON'T USE ++ IN THE PATH.
  • Now we need to set up some environment variables. The specific way for setting such variables depends of your version of Windows. For an explanation that covers the most general methods click here.
    • Set MINGDIR to C:\MinGW
    • Set UNIX_TOOLS to C:\unxutils\usr\local\wbin
    • Modify your PATH variable and add at the beginning of it C:\MinGW\bin;C:\unxutils\usr\local\wbin; (so, if your current PATH was PATH=C:\windows;C:\windows\command change it to PATH=C:\MinGW\bin;C:\unxutils\usr\local\wbin;C:\windows;C:\windows\command).
  • Since MinGW 2.0 the make command has been renamed to mingw32-make.exe. It's recommended to rename it to make.exe or make a copy of it with that name. For renaming it, just open Windows Explorer, go to the folder C:\MinGW\bin, right click on mingw32-make and select rename. Change the name to make and press enter (if your Windows Explorer shows extensions don't forget to add it back).
  • To compile Allegro you will need some DirectX headers that can be downloaded here. Decompress it in C:\MinGW (overwrite files if asked).
  • Open a console window (MS-DOS window) and type the following commands (remember to press enter at the end of each command):
    • c:
    • cd \mingw\allegro
    • fix mingw32
    • make
    • make install
  • If there wasn't any errors in the make and make install commands then you are done: Allegro is ready for being used. If you got some errors at that point, recheck that you followed all the steps and that you set the environment variables correctly. If you are still having problems try removing the UNIX_TOOLS environment variable and try again.
  • If you got MinGW Utilities, you can install a run-time debugger called Dr. MinGW that will help you with those horrible program crashes. For installing it open a console window and type drmingw -i. I recommend you to search in the web for GDB tutorials (GDB is the GNU Debugger which is a really good tool to help you find bugs in your code).

Now you can check that Allegro is working going to the C:\MinGW\allegro\examples folder and clicking a few .exe files.

Setting Dev-C++ up:

Now it's time for making Dev-C++ use your just installed MinGW.

Open C:\Dev-Cpp\devcpp.exe, then click Tools -> Compiler Options -> Directories. (If it's the first time you run Dev-C++, it will ask you what is the look you want it to use. Just select the one you want and click Next and then OK).

Now follow the next steps:

  • In the textbox that has a button with an ellipsis (...) type (or click the button and search the file): C:\MinGW\bin. Click Add.
  • Click the Libraries tab. It must have one entry already (C:\DEV-CPP\lib). Click that entry and then click Delete. Now type in the textbox C:\MinGW\lib, then click Add.
  • Click the C includes tab. It must have one entry already (C:\DEV-CPP\include). Click that entry and then click Delete. Now type in the textbox C:\MinGW\include, then click Add.
  • Click the C++ includes tab. it must have various entries already. Click each entry and then click Delete till the listbox gets empty. Now type in the textbox C:\MinGW\include\c++\x.x.x (where x.x.x is the g++ version you got. You should use the button with the ellipsis and search for the right version folder inside C:\MinGW\include\c++\). Click Add.
  • Click OK.

Now Dev-C++ is ready for being used as your IDE.

Compiling our first allegro program:

Let's make our first Allegro program!

Just copy and paste this example in any text editor or Dev-C++ and save it as allegro.c (you can save it with another name if you want to).

#include <allegro.h>

int main()
if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0))
allegro_message("Error setting GFX mode to 640x480");
return 1;
textout_centre(screen, font, "Hello Allegro World!", \

SCREEN_W / 2, SCREEN_H / 2, makecol(255, 255, 255));
return 0;

You have two choices for compiling it: using command line (a console), Dev-C++ or any other IDE.

Let's say you saved that file in C:\progs. If you want to compile it in a console, open a console window and type the following:

  • c:
  • cd \progs
  • gcc allegro.c -o allegro.exe -lalleg
  • allegro.exe

The first lines changes the default drive to C: if it wasn't there already, the second line enters to the folder progs that is in the root of C:, the third line compiles allegro.c with the GNU C compiler (gcc), outputs the executable as allegro.exe and links with the Allegro library (-lalleg).

If you want to compile it with Dev-C++, there're two ways: the project way and the simple file way.

I'll only explain the simple file one.

If you pasted that example in Dev-C++ and saved it with it you can jump to the next line, if not, open it with it first.

Click Tools -> Compiler Options and being in the Compiler tab check the checkbox that says Add these commands to the linker command line, then write in the multiline textbox -lalleg. Click OK.

Now click Execute -> Compile (you can also press Ctrl+F9 or click the Compile button in the tool bar). If you are using the WIP branch of Allegro, then it'll show you a warning after compiling it (it's related to the textout_centre function), even though the program will compile just fine. Now click Execute -> Run (you can also press Ctrl+F10 or click the Run button in the tool bar).

That program should set your screen to 640x480 and show a white message in the middle of your screen saying Hello Allegro World!, then you press any key and it returns to Windows. In case of an error it should show a message saying Error setting GFX mode to 640x480.

Setting the Environment Variables:

If you are using Windows 95/98/ME (some people has reported that allegro has problems compiling under Windows ME), you have two methods for doing it:

  1. Click Start -> Run and type msconfig. Click OK. Go to the tab autoexec.bat and click New. Write in the textbox SET MINGDIR=C:\MinGW and press enter. In the same way you can also add the UNIX_TOOLS environment variable. Click the last line of that list and then add a new one like this: SET PATH=C:\MinGW\bin;C:\unxutils\usr\local\wbin;%PATH%.
  2. Open a console and type the following commands:
    • c:
    • cd \
    • copy autoexec.bat autoexec.alg
    • echo SET MINGDIR=C:\MinGW >> autoexec.bat
    • echo SET UNIX_TOOLS=C:\unxutils\usr\local\wbin >> autoexec.bat
    • echo SET PATH=C:\MinGW\bin;C:\unxutils\usr\local\wbin;%PATH% >> autoexec.bat

    You can use the same console window you just opened for doing step 10 of the Step by step section. The only difference is that you have to execute c:\autoexec.bat just before any other command of step 10. Before you reboot you'll need to execute that line for every new console window before calling the GNU C Compiler, make or any other utility of MinGW.

    Most people recommends to restart Windows at that point (after executing the above commands), so you won't need to call autoexec.bat before compiling allegro.

    Note: autoexec.bat is a file that Windows executes when Windows boots, so it will set all the variables and execute all the commands in it, so they will be available when Windows finishes booting. If you change that file and don't reboot, the changes won't take effect till you reboot or you'll need to call that file explicitly every time you need to run a new console (no, it won't work if you run it thru Windows Explorer. It would just set the variables in the console window that it opens, but then it gets closed and everything comes back just as if nothing happened).

If you are using Windows NT/2000/XP, open Control Panel and click System. If you are using Windows XP you can just click Start, then right mouse button over My Computer then Properties.

The next pictures show you how to add a new environment variable (thanks to Cage from #allegro for the screenshots).

Click the Advanced tab, then click the Environment Variables button.

If you want to set the environment variables for all the users, click the button New (you have to be an administrator for this one), or if you want so set the environment variable for you as user, then click the button New.

Type the variable name you want to set and the value for it in the respective textboxes.

If you want to set the MINGDIR variable, type MINGDIR in the textbox for Variable name: and type C:\MinGW in the textbox for Variable value:.

If you have problems in this process, you can make a post in http://www.allegro.cc/ saying what is the problem and what is the error it returned, or you can get an IRC client, connect to the FreeNode network, join the channel #allegro and ask in there.