ACES
Computer Science
Development Environment: Code::Blocks with MinGW + Allegro
Friday, March 13, 2009 (Modified: March 22, 2009)
This is a how-to document on installing and configuring a build environment with an IDE for Allegro. The following instructions are tailored for WinXP, but also offer hints for Vista.
Part 1: Installing Code::Blocks, the IDE with MinGW
- It is recommended that you download and use the latest stable release of Code::Blocks with MinGW included (version 8.02): http://downloads.sourceforge.net/codeblocks/codeblocks-8.02mingw-setup.exe
- Run the setup file, choose Standard Install, and change the install directory to C:\CodeBlocks.
- Let the installation finish and move on to the next part.
Part 2: Configuring MinGW
- Open the System Environment Variables by hitting <Windows Key> + Pause/Break, select the Advanced tab, and hitting the Environment Variables button.
- Once the Env. Vars open up, add a new user environment variable named MINGDIR. Make the value be the same as you picked for step "1b". In this 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)
- Goto 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.
Part 3: Installing and compiling Allegro
- Download the latest version of Allegro: http://prdownloads.sourceforge.net/alleg/all422.zip?download and unzip this file into the main directory of your MinGW installation. (C:\CodeBlocks\MinGW)
- 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).
- Open a command prompt and cd to your Allegro directory (C:\CodeBlocks\MinGW\allegro)
- Run cmd> fix.bat mingw32 from this directory
- 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.)
- If you want to static link, you will also have to build Allegro to do that): Run cmd> mingw32-make STATICLINK=1
- Finally run cmd> mingw32-make install
- If it did not output errors, you are ready to go onto the next part. (Note that the copying of Allegro42.DLL to the Windows system32 directory will fail on default installations of Vista -- use Explorer to copy the file in this case.)
Part 4: Setting up the Compiler and Debugger in the IDE
- Start Code::Blocks. Click the Settings menu and select Compiler and Debugger...
- When the dialog opens, make sure that the GNU GCC Compiler is selected.
- Click the Toolchain Executables tab and make sure the path is correct (C:\CodeBlocks\MinGW in this case).
- Click the Search Directories tab and make the following additions:
- Sub-tab: Compiler: Add C:\CodeBlocks\MinGW\include and C:\CodeBlocks\MinGW\allegro\include
- Sub-tab: Linker: Add C:\CodeBlocks\MinGW\lib and C:\CodeBlocks\MinGW\allegro\lib\mingw32
- Sub-tab: Resource Compiler: Add C:\CodeBlocks\MinGW\include
- Click OK to close the dialog and move on to the next part.
Part 5: Allegro Templates
- Download the Allegro Code::Blocks Template and extract into your %APPDATA%/codeblocks/UserTemplates directory.
- To use the static linking capability of Allegro, choose the User Template "Allegro Static Link".
- To use the default dynamic linking (the application needs the allegro DLL) capability of Allegro, choose the User Template "Allegro Dynamic Link".
- The templates only include the examples at the end of this page, so you will need to modify or add more source files.
- 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()
#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()
#define ALLEGRO_STATICLINK
#include <allegro.h>
int main(void)
{
allegro_init();
allegro_message("Hello World!");
return 0;
}
END_OF_MAIN()
