The Allegro Wiki is undergoing maintenance, please be patient.
Windows, Code::Blocks and Allegro 5
The images shown in this tutorial are for reference only
Please note that you MUST install the matching compiler version with the version used to compile the Allegro libraries
For more information see Static and Dynamic Link
To install Allegro with the pre-built static binaries we're just going to need the Code::Blocks IDE, the MinGW installer, and the Allegro Binaries.
It is advised to get the latest version of these files to match the compiler: in this case, MinGW 4.7.0.
Note: While Code::Blocks comes with an embedded version of MinGW, it is recommended to use a standalone version such as the one linked above.
For more informations about these binaries go to The Allegro 5 Windows install guide
Inside the allegro-5.0.x-mingw-4.a.b 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.a 19 - libopenal-1.14-static-mt.a
The rest of the files inside of the "lib" folder can be safely ignored.
- 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. As this example is using the c++ language, remember to end the file 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 line to the "Other Linker options" section :
The linker page should look like this now:
- 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!!!.
If you wish to utilize C++11 with Allegro, you are unable to use the -std=c++11 option due to a bug with MinGW. Instead of checking the relevant check box in Compiler Settings->Compiler Flags, go to Compiler Settings->Other Options and put this line in:
For more information see: Static and Dynamic Link
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.
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.