The Allegro Wiki is migrating to github at

Build/Using precompiled binaries/MinGW

From Allegro Wiki
Jump to: navigation, search



For the purpose of this guide it's assumed you've got MinGW installed and your environment variables are set accordingly. If not, see MinGW. It's also assumed you're using a free IDE, e.g. Code::Blocks. The instructions describe the steps to take using Code::Blocks, but the process should be similar in other IDEs.

Make sure you've got a newer version of GCC

Open up a command prompt and type "gcc --version". If you've got a version prior to GCC 4.0.0, for example 3.4.5 which is bundled with Code::Blocks, then you'll need to update it. A precompiled version can be found on the MinGW download page - at the time of writing they had version 4.4.0 available. Download the appropriate "full" archive, extract, then copy/paste into your MinGW directory, overwriting files when prompted.

Download the Allegro binaries

Download the latest binaries from The ones for MinGW have MinGW in their filename. Extract the contents to somewhere that's appropriate (e.g. C:\Coding\Allegro\). If you've not already done so, get the DirectX files listed on and extract them to your MinGW directory.

Set up Code::Blocks

Start up Code::Blocks and create a new empty project.


Create and add a new source file named main.cpp(or .c), and copy the code below to it.

<highlightsyntax language="cpp">

  1. include <stdio.h>
  2. include <allegro5/allegro5.h>

int main() {

   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *bitmap;
   ALLEGRO_TIMER *timer;
   bool redraw = true;
   // Initialize Allegro
   if (!al_init()) {
       printf("Could not init Allegro.\n");
       return 1;
   // Install keyboard input.
   // Create a display with default settings, in a 800x600 resolution.
   display = al_create_display(800, 600);
   if (!display) {
      printf("Error creating display\n");
      return 1;

   // Create a timer at 60 FPS.
   timer = al_install_timer(1.0 / 60);
   // Create an event queue for receiving timer and keyboard input.
   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));
   al_register_event_source(queue, al_get_timer_event_source(timer));

   while (1) {
       ALLEGRO_EVENT event;
       al_wait_for_event(queue, &event);
       // Check for different conditions for closing the program using the
       // event queue.
       if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
       if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
           if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
       // Enable drawing the next frame.
       if (event.type == ALLEGRO_EVENT_TIMER)
           redraw = true;
       // Draw if the event queue is empty
       if (redraw && al_event_queue_is_empty(queue)) {
           redraw = false;
           al_clear_to_color(al_map_rgb_f(0.5, 0.5, 0.5));

   return 0;

} </highlightsyntax>

On the menu bar at the top, go to Settings->Compiler and debugger...

First, check that Code::Blocks Compiler's paths are set up correctly. Make sure it's pointing to the location of your MinGW compiler. (e.g. "C:\mingw") Toolchains.png

Go to the "search directories" tab and in the "compiler" section add the allegro include path e.g. "C:\Coding\Allegro\allegro-4.9.19-mingw-bin\include" In the "linker" section add the lib path e.g. "C:\Coding\Allegro\allegro-4.9.19-mingw-bin\lib"

Alternatively, if you copied the lib files directly to the MinGW lib folder, you can ignore adding custom paths to the linker.

When you're done, close that and, again on the menu bar at the top, go to Project->Build Options...


On the "Linker settings" tab, in the "link libraries" box, click the "Add" button, type "allegro" on it, and accept it. Click again and add "allegro_main" too. Notice that you're only linking to the core of the Allegro library. Refer to the other add-ons and link to the ones you think you'll need(e.g. allegro_image).


Close this menu when you're done, proceed to compile and run it.

Compile and run

Now you can build and then run the project (F9). You should get a 800x600 window filled with grey, which you can close pressing the ESC key or clicking on the Close button in the window. Now you're ready to make a program.