The Allegro Guide

General » Windows » Dev-C++ 5 » Using Allegro

I. Creating a Project

Using Allegro with Dev-C++ is simple once you get the workspace configured. For most applications, you will want to use a "Windows Application" and link against the optimized library. We are assuming you already have Allegro already installed for MinGW32.

A. Configuring a Windows Application

If you want to create a game with graphics, then you need to create a `Windows Application' workspace.

  1. Open Dev-C++
  2. Click on File / New / Project
  3. Choose Windows Application
  4. Enter your Project Name and hit "OK" (Fig. 1)

Your workspace has been created with a default `main.cpp' file containing pre-written code. You will not need any of that, because Allegro is much simpler and will hide the Win32 code from you. Remove all the text in the file.

The only thing left to do is to link to the Allegro library. You can either link to the library statically or dynamically. A static link will mean your executable will be larger, but the DLL will not be needed. A dynamic link will mean the executable is smaller, but the Allegro DLL must be distributed with the project. In short, you only need to do one or the other. If you are not sure, then linking dynamically is the safer option.

1. Dynamic Linking

  1. Click on the `Project' / `Project Options' menu
  2. Under Linking options enter `-lalleg'
  3. Click `OK' (Fig. 2)

2. Static Linking

  1. Click on the `Project' / `Project Options' menu
  2. Under Linking options enter `-lalleg -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound'
  3. Click `OK'

The workspace is entirely configured now! Click the `File' / `Save All' menu to save the project. Now, skip down to the section entitled "Compiling Source Code" to get your first program compiled.

II. Compiling Source Code

If you followed the steps above, you should already have a blank file called `main.cpp'. If not, create a new source file.

  1. Enter the following code:
    #include <allegro.h>
    
    int main(void)
    {
        allegro_init();
        allegro_message("Hello World");
        return 0;
    }
    END_OF_MAIN()
    
  2. Compile and Run the program. (F9)
If all went well, a message box appeared with the greeting `Hello, World'.