Windows Vista, Code::Blocks 10.05 and Allegro 5
From Allegro Wiki
The images shown in this tutorial are for reference only
Contents |
Static Link
For more information see Static and Dynamic Link
- Start
To install Allegro with the pre-built static binaries we're just going to need the Mingw installer and the Allegro Binaries.
The first thing we need to do is install Mingw. Then download the Allegro 5 Windows Binaries for MinGW 4.5.2 at Allegro.cc/files.
For more informations about these binaries go to The Allegro 5 Windows install guide
Choosing Files
Inside the allegro-5.0.5-mingw-4.5.2 folder we can see the next folders.
bin Include lib
The "lib" folder has some files that we're not going to use, so, we're going to keep the necessary ones. Since we're linking to Allegro statically, we can safely ignore the 'bin' folder.
Inside the "lib" folder we only need to use the files that end with the format "-static-mt", which are these :
Order is very important
1 - liballegro-5.0.5-static-mt.a
2 - liballegro_acodec-5.0.5-static-mt.a
3 - liballegro_audio-5.0.5-static-mt.a
4 - libvorbisfile-1.3.2-static-mt.a
5 - libvorbis-1.3.2-static-mt.a
6 - liballegro_color-5.0.5-static-mt.a
7 - liballegro_dialog-5.0.5-static-mt.a
8 - liballegro_font-5.0.5-static-mt.a
9 - liballegro_image-5.0.5-static-mt.a
10 - liballegro_memfile-5.0.5-static-mt.a
11 - liballegro_physfs-5.0.5-static-mt.a
12 - liballegro_primitives-5.0.5-static-mt.a
13 - liballegro_ttf-5.0.5-static-mt.a
-----------------------------------------------------------
14 - libdumb-0.9.3-static-mt.a
15 - libFLAC-1.2.1-static-mt.a
16 - libfreetype-2.4.4-static-mt.a
17 - libogg-1.2.1-static-mt.a
18 - libzlib-1.2.5-static-mt.
The rest of the files inside of the "lib" folder can be safely ignored.
Configuring Project
- Open Code::Blocks
- In the menu, select File->New->Project
- Select "Empty Project" and then "Go"
- Enter a project title and a destination folder
- Make sure "Create Debug configuration" and "Create Release configuration" are both selected
- Select File > New > Empty File
- Press "yes" to add the file to the current project.
- Enter a name for the file and save it. Remember to end it with ".cpp" instead of ".c".
- Select "Debug" and "Release" configurations.
Linking to Allegro 5 Statically
- Right click on the project name in the left hand pane and select 'Build Options' or use the menu and go to Project->Build Options
- Select the "Linker Settings" tab and press "Add"
- Select all the Allegro static libraries
Since we're linking statically, there are other system libraries that we need to link to. You can find them all inside the directory C:\MinGW\lib. The list of libraries follows :
Note: If you can't find some of these files it is very likely that your MinGW installer didn't correctly download GCC. Re-running the MinGW installer may solve this problem.
Order is very important
1 - libgdiplus.a
2 - libuuid.a
3 - libkernel32.a
4 - libwinmm.a
5 - libpsapi.a
6 - libopengl32.a
7 - libglu32.a
8 - libuser32.a
9 - libcomdlg32.a
10 - libgdi32.a
11 - libshell32.a
12 - libole32.a
13 - libadvapi32.a
14 - libws2_32.a
15 - libshlwapi.a (Not needed in the versions previous to 5.0.4)
It might take you a while to find them, so use the search box.
- Add the following lines to the "Other Linker options" section :
Note : This does not apply to older versions of MinGW. Less than 4.5.0?
-lgcc_eh
-static-libgcc
-static-libstdc++
You should see something like this. And remember that the order is important.
- Go to the "Search directories" tab and select the "Compiler" tab below it. Now add the "include" folder to it.
And remember when using the static version of Allegro you must define ALLEGRO_STATICLINK before including any Allegro headers. You can do this manually in your own code, or you can use the menu by going to Project->Build Options->Compiler Settings->#defines and add the entry ALLEGRO_STATICLINK to it.
#include <iostream>
#define ALLEGRO_STATICLINK
#include "allegro5/allegro.h"
#include "allegro5/allegro_font.h"
#include "allegro5/allegro_ttf.h"
#include "allegro5/allegro_image.h"
#include "allegro5/allegro_primitives.h"
etc...
Code::Blocks detects the compiler automatically, but if you have a problem make sure Code::Blocks knows where the MinGW files are and then press "Auto-detect".
Now you are ready to code!!!.
Dynamic Link
For more information see: Static and Dynamic Link
- Start
Follow the same instructions to install Allegro 5 statically but instead of use the files which end with "-static-mt.lib" use those which ends with "-md.dll", you'll find them inside the bin folder.
You're doing a dynamic link so you don't need to define ALLEGRO_STATICLINK, you don't need to put anything at "Other Links Options" section and you don't need to link to "libdumb-0.9.3-static-mt.a", "libFLAC-1.2.1-static-mt.a", "libfreetype-2.4.4-static-mt.a", "libogg-1.2.1-static-mt.a" or "libzlib-1.2.5-static-mt.libvorbis".
Remember always to place the Allegro binaries in the same directory as the executable program, and distribute it with them.
Debug Mode and Monolith
Allegro, as many other libraries offers you the possibility to use binaries optimized for debugging, those binaries allow you to generate an "allegro.log" file which can be used to detect problems inside your application. As you can see each binary has a static, dynamic and debug mode. But you'll also find a Monolith version winch has all the binaries inside of it. That's it by linking to this library you have all the capabilities of allegro ready to use. If you're using all the addons, the Monolith binary should be the right option. If you're not using all the addons but for some reason you still want the Monolith version, don't worry, linking to the static Monolith version it's the same as linking to all the static lib files separately as we did before, our executable file it's going to preserve the same size since static linking alway use the portion of code necessary to execute our application.
Our setup to use the Monolith-Static-MT-Debug library should be like this:
1 - liballegro-5.0.5-monolith-static-mt-debug.a
-----------------------------------------------------------
2 - libvorbisfile-1.3.2-static-mt-debug.a
3 - libvorbis-1.3.2-static-mt-debug.a
4 - libdumb-0.9.3-static-mt-debug.a
5 - libFLAC-1.2.1-static-mt-debug.a
6 - libfreetype-2.4.4-static-mt-debug.a
7 - libogg-1.2.1-static-mt-debug.a
8 - libzlib-1.2.5-static-mt-debug.a
-----------------------------------------------------------
9 - libgdiplus.a
10 - libuuid.a
11 - libkernel32.a
12 - libwinmm.a
13 - libpsapi.a
14 - libopengl32.a
15 - libglu32.a
16 - libuser32.a
17 - libcomdlg32.a
18 - libgdi32.a
19 - libshell32.a
20 - libole32.a
21 - libadvapi32.a
22 - libws2_32.a
And in Other Linker Options, the same as previous static link.
-lgcc_eh
-static-libgcc
-static-libstdc++
Linking to the dynamic version of Allegro is the easiest thing in this world, since the only thing you have to do is just link to "allegro-5.0.5-monolith-md.dll" and with only that you have all the features of Allegro. Remember always to place the binary in the same directory as the executable program.


