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 188.8.131.52 are not tailored for the following instructions and will not work.
Part 1: Installing Code::Blocks 10.05, the IDE with MinGW
- 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
- 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.
- Let the installation finish and move on to the next part.
Part 2: Configuring MinGW
- Open the System Environment Variables by pressing <Windows Key> + Pause/Break, select the Advanced system settings link, and click the Environment Variables button.
- 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)
- 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 184.108.40.206
- Download Allegro 220.127.116.11 (stable): http://sourceforge.net/projects/alleg/files/allegro/18.104.22.168/all4231.zip/download and unzip the contents 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. 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
- Start Code::Blocks 10.05. Click the Settings menu and select Compiler and Debugger...
- When the dialog opens for the first time, verify that the GNU GCC Compiler is selected.
- 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).
- 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. 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.
- 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.
- 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.
- 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.
- Just to check, try this sample code (as shown in the Allegro documentation - both dynamic and static versions shown):