The Allegro Wiki is migrating to github at

Windows, Visual Studio 2010 and Allegro 5

From Allegro Wiki
Jump to: navigation, search


This guide explains how to get up and running with Allegro 5. This setup assumes that there is no existing compiler installed. It is recommended to have a good foundation with C/C++ before starting with Allegro. A Microsoft Visual Studio 2010 installation guide is included. If Visual Studio is already installed, goto the Installing Allegro 5 section.

We will step through the process of installing Microsoft Visual Studio 2010 Express, which is a free and featured C/C++ IDE from Microsoft. After that, we will download and install Allegro 5, create a new project, and build a small Allegro 5 example.

As a note, when you see "5.0.x" in this article, the x is to be replaced by your current Allegro sub-version.

Installing Microsoft Visual Studio 2010 Express


Screenshot of the MSVC 2010 download link.
Downloading MSVC 2010.

Download Visual C++ 2010 Express from Microsoft's website. It is free to download and use, and works great with Allegro 5: Microsoft Visual C++ 2010 Express(MSVC)

Run the MSVC 2010 Installer

Screenshot of the MSVC 2010 installation.
Installing MSVC 2010.

Continue through the setup.

Visual C++ 2010 is Ready

Screenshot of the MSVC 2010 Start Page.
Visual C 2010 Start Page.

You should now be able to start Microsoft Visual C++ 2010 Express, and see the Start Page.

Installing Allegro 5


Download the latest version of Allegro 5 from's download page.

Be sure to select the binary version that corresponds with your version of MSVC.

This tutorial may reference an older version number than what is available on that page. While following the instructions, if you copy and paste something with a version number, be sure to update it to reflect the version you downloaded.

Install Allegro 5 Headers and Libraries

Open and extract the folders include, lib and bin to some place of your choosing. We will assume you've chosen c:\allegro as the base location for those three folders. We will later add this path to our project so VC can find Allegro.

Note: Never copy anything into a system folder (like a path starting with C:\Program Files or C:\Windows). Those locations should generally be considered read-only unless using a proper installation "wizard." Keeping Allegro in its own folder will help you keep track of which version(s) you have installed. Also note that copying a DLL into system32 is not proper because a) you may overwrite an incompatible DLL and b) it's not even the right location on 64-bit systems.

Using Allegro 5

Create a New Project

Screenshot. Creation of an empty MSVC 2010 project.
Creating a new MSVC 2010 Project.

Start Microsoft Visual C++ 2010 Express.

Click New Project on the Start Page.

Make sure Visual C++ is selected on the left. Now select Empty Project in the middle. Type a name for your project at the bottom, and feel free to change where your project is located. Click Ok to create your project.

Add Some Source Code

Screenshot. Selecting Add New Item for a MSVC 2010 Project.
Add New Item...
Screenshot. Creating a blank C++ file called main.cpp.
Create a blank C++ file called main.cpp.
Screenshot of the basic Allegro 5 MSVC 2010 project, including main.cpp.

Just to get you started, we will add some simple code to your project that initializes the Allegro 5 library and opens a window.

Right click your project, under Solution Explorer on the right, and select Add->New Item...

Make sure Visual C++ is selected on the left. Select C++ File (.cpp) in the middle, and name your file main.cpp. Click Add.

Now copy and paste the following code into your new file:

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv)

   if(!al_init()) {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;

   display = al_create_display(640, 480);
   if(!display) {
      fprintf(stderr, "failed to create display!\n");
      return -1;




   return 0;

Save main.cpp.

Setup Project For Allegro 5

Screenshot. Selecting Project Properties in MSVC 2010.
Project Properties.
Screenshot. Updating Additional Dependencies in MSVC 2010 for Allegro 5.
Adding Allegro 5 to the Additional Dependencies.

For any project you create that uses Allegro 5, you must tell Visual C++ to link your project with the Allegro 5 library.

Right click your project under Solution Explorer on the right. Select Properties.

  • Under Configuration Properties->C/C++->General, enter c:\allegro\include in Additional Include Directories.
  • Under Configuration Properties->Linker->General, enter c:\allegro\lib in Additional Library Directories.
  • Under Configuration Properties->Linker->Input, append allegro-5.0.x-monolith-md-debug.lib to Additional Dependencies.
  • Under Configuration Properties->Debugging, enter PATH=c:\allegro\bin;%PATH% in Environment.
  • Click Apply.

Visual C++ can now link your project with the Allegro 5 library.

You should now select the "Release" configuration (upper left corner) and repeat the steps with one minor change: use the non-debug library allegro-5.0.x-monolith-md.lib.

The monolith dll has the main Allegro module and all addons bundled into one file. If instead, you only want to add the main Allegro library and the ones for the addons you use, in order to save space, you need to add allegro-5.0.x-md-debug.lib as well as allegro_(addon)-5.0.x-md.debug.lib.

Build Your Project

Screenshot of a successful MSVC 2010 compile.
Successful Build.

Now let's have the Visual C++ compiler turn your beautiful new code into a program!

Simply click the Debug menu at the top, and select Build Solution

If everything has gone well so far, you should see a successful message at the bottom of the MSVC 2010 window.

Run Your Project

Screenshot of the simple Allegro 5 project running under MSVC 2010.
Your beautiful black window!

Now to actually run your shiny new Allegro 5 program. Click the Debug menu at the top and select Start Debugging.

A black window should show up.

That is your first Allegro 5 window! It does not do much right now. It will display for 10 seconds, and then close automatically.

Static linking

But wait, this method is for dynamic linking. What if you want it so MSVCR100.dll and the Allegro libraries come packaged with the executable? You'll have to change some things. You can do this just for the Release configuration, no need to do it for the Debug one.

  • Add the following libraries to the linker in Configuration Properties->Linker->Input:
    • (Your standard Allegro library(ies), but with the -static-mt suffix. So, for instance, allegro_image-5.0.x-static-mt.lib. This can be the monolith dll, or all addons separated.)
    • dumb-0.9.3-static-mt.lib
    • freetype-2.4.8-static-mt.lib
    • libFLAC-1.2.1-static-mt.lib
    • libogg-1.2.1-static-mt.lib
    • libvorbis-1.3.2-static-mt.lib
    • libvorbisfile-1.3.2-static-mt.lib
    • openal-1.14-static-mt.lib
    • zlib-1.2.5-static-mt.lib
    • winmm.lib
    • opengl32.lib
    • gdiplus.lib
    • psapi.lib
    • shlwapi.lib
  • On the Configuration Properties->Linker->Input dialog box, leave the "inherit from parent or project defaults" option checked.
  • In Configuration Properties->C/C++->Code Generation->Runtime Library, set that to "/MT" (or "/MTd" for the Debug configuration).
  • In Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions, add ALLEGRO_STATICLINK to the list.
    • Alternately, add #define ALLEGRO_STATICLINK to the top of your main file, before you include anything Allegro-related.

This option is sometimes preferred, given that with dynamic linking, you'll have to distribute the dlls with the executable. This isn't normally a problem, but given that there are 2 versions of MSVCR100.dll, the 32-bit and 64-bit one, you can't distribute them both (as they have the same name).

You might want to see if it runs on a machine that doesn't have the Visual C++ Runtimes nor Allegro installed, to see if this single executable can run without the need of any .dll file. There's always a chance something can go wrong.

You'll need to have the Microsoft SDKs installed in order to compile like this. In addition, if you aren't going to use audio on your program, you won't need libraries like libogg or libvorbis, so if you want to save space, remove some libraries that you think aren't needed, and see if it compiles.

What's Next?

Follow along with the Allegro 5 Tutorial to learn how to do more with the Allegro 5, and eventually make your own video game!