Cross Compile Allegro 5 Programs in Linux for Windows
The Allegro game programming library has released v5 of their popular library and with it comes a whole mess of great changes. Thing is, since most of the applications you make with it are going to be games, your main audience lives in Windows. Since I am really upset with Microsofts offerings in this area I needed a way to capture this audience without having to drive myself insane.
What follows is how I am making Windows executables in Linux using Allegro. Please note that I live in Ubuntu (currently 10.10, Maverick Meerkat). You may have to make some slight changes to fit your distro but that should not be a big deal. These instructions assume a clean installation where no other copy of Allegro has been installed (not sure if that would be a problem or not as I have not tested).
- Install the required programs:
sudo apt-get install cmake mingw32
- Retrieve and uncompress DirectX:
Download and copy the DirectX headers and libraries to
/usr/i586-mingw32msvc/. Note the file structure within the archive should compare to the mentioned directory. When prompted to overwrite any files do so but make sure you have a backup first in case something explodes.
- Retrieve and uncompress Allegro 5:
Download allegro-5.x.x.tar.gz from their site. Uncompress some place easy to get to. I used my desktop as we can delete this when done.
- Compile from source:
In a terminal type
cd [path to uncompressed archive] && mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw.cmake .. && make && sudo make install
This may take a little while depending on your hardware.
You should now have a functioning cross compiler setup for Allegro 5. Just replace
i586-mingw32msvc-g++ (for example, I compiled my first test with
i586-mingw32msvc-g++ alleg.cpp -lallegro.dll -lallegro_image.dll -lallegro_font.dll -o alleg.exe). The DLLs you will need are in
/usr/i586-mingw32msvc/bin/. You may now delete all of our working files on your desktop (or wherever you put them).
There are still one or two things I need to figure out. For one, dynamically linked programs are peachy on Linux; I am comfortable in my assumption that most people using Linux either already expect this or are willing to learn. Windows, not so much. I want to statically link for that platform but I have yet to experiment with that. Another thing is the fact that my current method has Windows opening up a console window in addition to the “main” window. I am sure this is also very simple but have not yet played with it.
7 thoughts on “Cross Compile Allegro 5 Programs in Linux for Windows”
I have been searching all week to know how to cross-compile anything from linux for windows and now I get exactly what I was looking for trough a simple search on allegro.cc. Thanks!
Will this work for Allegro 4.2 or 4.4?
Only one way to find out.
Thank you very much. This was immensely helpful and got me right where I wanted to be. Much thanks!
Using -Wl,–subsystem,windows as a G++ command line option got rid of the console for me.
What about the libraries needed to compile allegro? Where are they built?