Building Allegro 4 with MinGW

From Allegro Wiki
Jump to: navigation, search

This page is to provide an up to date version of the instructions for building Allegro 4.4.3 from GIT as of August 6th, 2017.

For historical purposes you can try to follow the old guide below, but this is no longer recommended as it is out of date. However, it may be useful for old versions of MinGW, so it is noted here. I advise you to upgrade to a more recent version of mingw unless you have no other choice. See "Installing MinGW" below.

Build Requirements

To build Allegro 4.4.3+ on Windows with MinGW you will need several things. Required build tools are MinGW, CMake, GIT, and MSYS (for optional dependencies), as well as DirectX 8 or higher development libraries.

Note : The Jun 2010 DXSDK and later versions do NOT include DirectDraw, which is necessary to build Allegro 4 on Windows.

MinGW Compiler

Before we can build with MinGW, we need a working MinGW compiler. See the following page for details getting setup with MinGW :

DirectX headers and import libraries

If your version of MinGW doesn't come with DirectX, you will need to download from here :

[http://] (TODO : Fix this link)

Extract the contents to a separate folder for later use.

CMake Build System

Next step is to install CMake. Get it from the following link :

GIT Versioning Control System

You will also need GIT for fetching the latest code from Get it here :

MSYS Minimalist posix SYStem

MSYS is required to build some of the dependencies for Allegro 4.4.3+, such as libogg and libvorbis. Read about MSYS on the wiki here :

Version 1.0.11 works just fine, so don't worry about getting the latest version.

You will need the following three components for MSYS :

Run MSYS-1.0.11.exe and install to c:\msys. Next, run msysDTK-1.0.1.exe and point the install to c:\msys. After that, extract msysCORE-1.0.11-bin.tar.gz twice and copy the contents to c:\msys\1.0 .

You can now test MSYS by running its shortcut from the desktop.

These are all the tools you will need to build Allegro. Let's get started.

Building optional dependencies for Allegro 4.4

Allegro 4 now comes with several add-on libraries to make life easier for you. These include AllegroGL, an OpenGL driver for Allegro, Logg, a library to play and stream .ogg files, jpgalleg, which allows you to load .jpg image files, and loadpng, a library to load .png files.

However, these add-on libraries introduce some dependencies on third party libs, such as libogg, libvorbis, and libpng (which itself depends on zlib).

Get them here :

We'll need to build zlib, libpng, ogg, and vorbis, in that order. libpng depends on zlib, and vorbis depends on ogg.

Building ZLIB and LibPNG with CMake

zlib and libpng will be built with CMake.

Steps :

  1. Open a MinGW command prompt
  2. Make a copy of the zlib or libpng source folder and cd to this location
  3. Make a sub-directory called build and cd to this directory
  4. Run CMake and configure zlib or libpng as necessary
  5. Run mingw32-make and mingw32-make install

Once you have your MinGW environment running, enter the following commands, replacing c:\path\to\library with the directory that contains the zlib or libpng source folder :

>copy c:\path\to\library\lib c:\
>cd /d c:\lib
c:\lib>mkdir build
c:\lib>cd build
c:\lib\build>cmake-gui ..
(Configure cmake options here, see below)
c:\lib\build>mingw32-make install

Configuring ZLIB with CMake

The zlib cmake file is a little wonky. You will have to adjust several of the cmake variables to build zlib properly.

Once you run 'cmake-gui ..', you will be greeted with the cmake gui program.

First, hit the configure button on the bottom left, and select 'MinGW Makefiles' for the generator and use the native compiler option. Go through each of the options and set the correct values, and then hit the 'generate' button. This will generate makefiles for you, which you then use to build zlib as shown above.

Enter the correct options in CMake for your system now. At a minimum, you will want to set these 4 variable values :

  • CMAKE_BUILD_TYPE (Valid options are 'Release' and 'Debug')
  • INSTALL_BIN_DIR (DLLs will be installed here - usually this is your compiler's bin directory)
  • INSTALL_INC_DIR (Include files will be installed here - usually this is your compiler's include directory)
  • INSTALL_LIB_DIR (Library files will be installed here - usually this is your compiler's lib directory)

You may need to set the directories for INSTALL_MAN_DIR and INSTALL_PKGCONFIG_DIR before generating makefiles as well.

Once generate completes successfully, you will want to run mingw32-make and mingw32-make install to complete the building of zlib.

Configuring LibPNG with CMake

When you get to the CMake configuration step, these are the variables you will need to set to build libpng :

  • CMAKE_BUILD_TYPE ('Release' or 'Debug')
  • CMAKE_INSTALL_PREFIX (Usually c:\mingw)
  • ZLIB_INCLUDE_DIR (Usually c:\mingw\include)
  • ZLIB_LIBRARY_DEBUG (Only necessary if you are trying to debug libpng and zlib)
  • ZLIB_LIBRARY_RELEASE (Usually c:\mingw\lib\libzlib.dll.a)

Once you finish generating the makefiles for libpng, run mingw32-make and mingw32-make install as before.

Building OGG and VORBIS with MSYS

Note: MSYS uses make, not mingw32-make. If you use mingw32-make it is almost guaranteed not to build correctly.

Steps for building libogg and libvorbis are similar to the steps for zlib and libpng, but we will be using MSYS and configure instead of CMake.

General steps :

  1. Make a copy of the libogg and libvorbis source folders wherever you like
  2. Start an MSYS session, and cd to the location you made copies of ogg and vorbis
  3. Create a build directory and cd to it
  4. Run configure
  5. Run make and make install

Using configure is usually pretty simple. The only thing you usually need to set is the install prefix, which decides where you want your libraries to be installed. This can be done by passing '--prefix=/c/mingw' to configure, substituting your own compiler directory for /c/mingw or another directory to keep your install clean. Be advised however, vorbis only looks for ogg in /c/mingw, and I don't know how to tell it to look somewhere else.

Command line steps :

>cp /c/path/to/library/lib /c/
>cd /c/lib
/c/lib>mkdir build
/c/lib>cd build
/c/lib>../configure --prefix=/c/mingw
/c/lib>make install

You should now have working installed binaries for zlib, libpng, libogg, and libvorbis.

Building Allegro 4.4.3+

Here are the general steps for building allegro 4 from GIT :

  1. Open a MinGW command prompt
  2. Clone Allegro from GIT and checkout version 4.4
  3. cd to your allegro directory, create a build folder, and cd to it
  4. Run CMake and configure allegro
  5. Generate the makefiles in CMake
  6. Run mingw32-make and mingw32-make install

Command line steps to build allegro :

>mkdir allegro4
>cd allegro4
c:\allegro4>git clone
c:\allegro4>cd allegro
c:\allegro4\allegro>git checkout 4.4
c:\allegro4\allegro>git pull
c:\allegro4\allegro>mkdir build && cd build
c:\allegro4\allegro>cmake-gui ..
(Configure CMake and Allegro 4 here)
c:\allegro4\allegro>mingw32-make install

Configuring Allegro 4.4 with CMake

There are several important variables in the Allegro 4 CMake environment that should always be configured :

  • SHARED (Check to enable the dynamic build of allegro, leave unchecked to build the static version)
  • CMAKE_BUILD_TYPE (Valid options are 'Release', 'Debug', and 'Profile')
  • CMAKE_INSTALL_PREFIX (Where you want allegro 4.4 to be installed)

The rest of the options depend on your compiler setup and where you installed your dependencies. When you hit 'configure', cmake will try and guess at what these options should be. You may need to change options and hit configure several times before it will generate properly.

You will most likely need to tell CMake exactly where to find your DirectX headers and libraries. Variables to set include :

  • DXGUID_LIBRARY (set this to the path to your version of libdxguid.a)
  • DDRAW_INCLUDE_DIR (typically c:/mingw/include or for mingw-w64 c:/mingw/i686-w64-mingw32/include)
  • DDRAW_LIBRARY (set this to the path to your version of libddraw.a)
  • DINPUT_LIBRARY (set this to the path to your version of libdinput.a or libdinput8.a)
  • DSOUND_INCLUDE_DIR (see above)
  • DSOUND_LIBRARY (set this to the path to your version of libdsound.a)

After that, configure all the include directories for your desired dependencies, and set the release library for each one as well.

Hit generate.

If all goes well, you will see 'configuration done' and 'generating done'. You can now return to the command line and run mingw32-make and mingw32-make install to complete the process.

You should now have binaries for allegro ready to go! Repeat steps 4 thru 6 for each version of Allegro that you wish to build, depending on whether it is dynamic or static and whether or not it is a release or a debugging build.

NOTE : If you want to build the static libraries, you will need to set the release library
       for each dependency to its static version and possibly append '-static-libgcc' and '-static-libstdc++'


Enjoy Allegro 4!