SJESoft.com logo.

ACES

Computer Science

Development Environment: Code::Blocks with MinGW + Allegro


This is a how-to document on installing and configuring a build environment with an IDE for Allegro. The following instructions are focused on Windows Vista, but should not differ considerably on Windows 7. Take careful note of the versions of all software mentioned in this document as Allegro versions past 4.2.3.1 are not tailored for the following instructions and will not work.

 

Part 1: Installing Code::Blocks 10.05, the IDE with MinGW

  1. It is recommended that you download and use the latest stable release of Code::Blocks with MinGW included (version 10.05): http://prdownload.berlios.de/codeblocks/codeblocks-10.05mingw-setup.exe
  2. Run the setup file. Make sure MinGW Compiler Suite is checked on the "Choose Components" screen. Change the install directory to C:\CodeBlocks on the Choose Install Location screen.
  3. Let the installation finish and move on to the next part.

 

Part 2: Configuring MinGW

  1. Open the System Environment Variables by pressing <Windows Key> + Pause/Break, select the Advanced system settings link, and click the Environment Variables button.
  2. Once the Environment Variables open up, add a new user environment variable named MINGDIR. Make the value be the same as you picked for step "1b". In our case it would be C:\CodeBlocks\MinGW. (Note: You will also have to add C:\CodeBlocks\MinGW\bin to the PATH to make the compiler work)
  3. Go to the command prompt and type gcc -v to test the installation. If it outputs version information associated with your version of compiler, you are ready to go onto the next part. Your compiler should report version 4.4.1

 

Part 3: Installing and compiling Allegro 4.2.3.1

  1. Download Allegro 4.2.3.1 (stable): http://sourceforge.net/projects/alleg/files/allegro/4.2.3.1/all4231.zip/download and unzip the contents into the main directory of your MinGW installation. (C:\CodeBlocks\MinGW)
  2. Download the DirectX 7 SDK http://alleg.sourceforge.net/files/dx70_mgw.zip or the DirectX 8 SDK http://alleg.sourceforge.net/files/dx80_mgw.zip and extract it into the main directory of your MinGW installation (C:\CodeBlocks\MinGW).
  3. Open a command prompt and cd to your Allegro directory (C:\CodeBlocks\MinGW\allegro)
  4. Run cmd> fix.bat mingw32 from this directory
  5. Run cmd> mingw32-make (it may be easier to rename C:\MinGW\bin\mingw32-make.exe to make.exe and substitute throughout the remainder of this document.)
  6. If you want to static link, you will also have to build Allegro to do that): Run cmd> mingw32-make STATICLINK=1
  7. Finally run cmd> mingw32-make install
  8. If it did not output errors, you are ready to go onto the next part. If, however, you see that the copying of allegro42.dll to the Windows system32 directory failed creating an Error 1, use Explorer to copy the file in this case (copy C:\CodeBlocks\MinGW\allegro\lib\mingw32\allegro42.dll to the C:\WINDOWS\System32 directory).

 

Part 4: Setting up the Compiler and Debugger in the IDE

  1. Start Code::Blocks 10.05. Click the Settings menu and select Compiler and Debugger...
  2. When the dialog opens for the first time, verify that the GNU GCC Compiler is selected.
  3. Click the Settings menu and then Compiler and Debugger... Under the Global compiler settings, click the Toolchain executables tab and make sure the path is correct for the GNU GCC Compiler (C:\CodeBlocks\MinGW in this case).
  4. Click the Search directories tab and make the following additions:
    1. Sub-tab: Compiler: Add C:\CodeBlocks\MinGW\include and C:\CodeBlocks\MinGW\allegro\include
    2. Sub-tab: Linker: Add C:\CodeBlocks\MinGW\lib and C:\CodeBlocks\MinGW\allegro\lib\mingw32
    3. Sub-tab: Resource Compiler: Add C:\CodeBlocks\MinGW\include
  5. Click OK to close the dialog and move on to the next part.

 

Part 5: Allegro Templates

  1. Download the Allegro Code::Blocks Template. Its unzipped destination will be %APPDATA%/codeblocks/UserTemplates directory or in other words C:\Users\<insert account name here>\AppData\Roaming\codeblocks\UserTemplates. By default, the UserTemplates directory will not exist, so you should create it first before you unzip the file into it.
  2. To use the static linking capability of Allegro, open Code::Blocks 10.05 and click File->New->Project... Choose the User Template "Allegro Static Link" and click “Go”. Follow the rest of the onscreen instructions.
  3. To use the default dynamic linking (the application needs the allegro DLL) capability of Allegro, open Code::Blocks 10.05 and click File->New->Project... Choose the User Template "Allegro Dynamic Link" and click “Go”. Follow the rest of the onscreen instructions.
  4. The templates only include the examples at the end of this page, so you will need to modify or add more source files to create more complex projects.
  5. Just to check, try this sample code (as shown in the Allegro documentation - both dynamic and static versions shown):

 

// For dynamic linking

#include <allegro.h>
int main(void)
{
    allegro_init();
    allegro_message("Hello World!");
    return 0;
}
END_OF_MAIN()

 

// For static linking

#define ALLEGRO_STATICLINK

#include <allegro.h>
int main(void)
{
    allegro_init();
    allegro_message("Hello World!");
    return 0;
}
END_OF_MAIN()