The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

Setting up Code::Blocks with Allegro on XP

From Allegro Wiki
Jump to: navigation, search

Setting up Allegro to use in Conjuction with Codeblocks and MinGW32 on Windows XP

This is a guide to getting oneself in a position to make programs which make use of the allegro library. It's aimed at newcomers to game programming and so although it will require a degree of common sense to follow effectively, I'll try to make it as clear and simple as possible.

Before starting out though, a file compression/decompression utility is required.

7-zip can handle all the files involved and is truly freeware.

Here's the link to the download page :- 7-zip download page.

Get that installed you're ready to start.


STEP 1 - Installing the MinGW Compiler

To make allegro programs a C or C++ compiler is required. The allegro library (of functions) is written in C and programs that use it need to be written in C too (or C++). The compiler is crucial. Fortunately there's a free compiler going called MinGW.

This link :-

MinGW files

takes you to part of a page with 7 download links on it found under the heading :-

              Base System with C++

Create a directory C:\mingw. This is where all the files will be extracted to.

Click on each link on the download page and save each file to your Desktop. Next, because these files are .tgz files and 7-zip can only completely extract them in two stages (first ungzip-ping, then untar-ing) an intermediary folder needs to be made to put the .tars in. So make a folder on the desktop. Call it anything you want. Then use 7-zip to extract the files on the desktop into this folder. When that's done go to the folder and extract all the files in it to C:\mingw


Next you need to set up some environment variables.

To do this, click on start, then control panel, then the system icon. Click on the advanced tab and then on the environment variables button. Under 'system variables' click new.

Enter the name as MINGDIR and the value as C:\mingw (assuming that's what you called the directory where you installed mingw). When that's done find the variable called 'Path' in the list, highlight it and click on edit. Then, at the beginning of it's value, type in C:\mingw\bin; then click OK.

STEP 2 - Installing The Allegro Library

  • Please note that the installation instructions here apply only to Allegro versions up to 4.2.2.
  • For installation instructions for Allegro version 4.4 or later, please read the readme.txt file as well as the corresponding file for your compiler in the /docs/build folder of the Allegro distribution.


Next since the aim here is to be able to write allegro programs, you need to get the allegro library. The way this guide installs it is by downloading the latest stable source and compiling it.

First though, open a console (START->run, type in cmd and click OK) change the directory to C:\mingw or to wherever you installed MinGW and type in gcc -v.

You should see something like this :-

Console picture.png

Assuming you get output looking something like this, the compiler is installed properly. If not, something went wrong. Follow the previous steps again or contact the allegro.cc forums with the details.

Next follow this link to get the latest allegro source zip file for Windows.

The Allegro Homepage

There's usually a link to the download section from the News part of the page.

You need to download the file which is stable, contains the source code not binaries and is in a DOS/Windows friendly format (.zip).

Once you've got that unzip it in C:\mingw. A new folder should appear there for allegro.

Next, you need to download a directX package. This is because the Windows version of allegro uses directX (the standard Windows way of interfacing graphics). Allegro won't compile without it.

Here's the link to download it.

dx70_mgw.zip

Extract the contents to C:\mingw overwriting all files.

Open a console again. Get to C:\mingw\allegro and type in fix mingw32.

Now allegro can be compiled by typing in the command mingw32-make. Watch allegro compile or make a cup of tea or something. When it's done you just need to install it. Type in mingw32-make install.

STEP 3 - Installing Code::Blocks

This guide uses the stable release of Code::Blocks. This can be found here

Follow the Windows 2000/XP/Vista link.

Download it to the Desktop and then click on the icon to install it.

When Code:Blocks opens, click Settings->Compiler and debugger... and click on the Toolchain Executables. This should like this :-

Toolchains.png

If that's how it looks you should be ready to start compiling allegro programs.

Compiling an Allegro Program

Create a new folder on the C: drive for storing your projects.

For an example, start a new project by clicking on Create a new project on the Code::Blocks opening screen. Choose console application and then click on GO. A wizard should open. Choose C for the language. On the next page choose a name for the project (perhaps 'test'). Where it says 'Folder to create project in' click the button to the right and browse to the folder made for projects, C:\projects if that's what you called it. Click next and then tick the box next to Create Release Configuration. Click next.

Under where it says management click on the little plus next to where it says Sources and then click on main.c .

Write yourself a little allegro program or replace the main.c in the projects folder with this file :

File:Main.c

Once you've done that, on the top menu click Project->Build options and on the window that appears click on the linker swettings tab. Click the Add button.