Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Noobs guide to installing allegro 5 in MinGW

This thread is locked; no one can reply to it. rss feed Print
Noobs guide to installing allegro 5 in MinGW
Levi Harman
Member #14,335
May 2012

Noobs guide to installing Allegro with Mingw on windows 7.
I will try to include all the information you need to get it running and compile your first program.

For this guide I am using mingw
I installed MinGW with mingw-get-inst-20120426 (download the mingw-get-inst-20120426.exe file when you open the folder.) LINK:
http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/

Here is a link to the official guide to installing mingw, I only suggest looking at it if I forget to mention something. You might want to read over it but I plan on mentioning everything in this post.
LINK:http://www.mingw.org/wiki/Getting_Started

After you install mingw-get-inst-"version number" (I am using mingw-get-inst-20120426) run the .exe and click next until you get to Repository Catalogues. Check the 'Use pre-packaged repository catalogues' then click next. Accept the agreement. I recomend installing to C:\MinGW
When you get to the select components option check C compiler, c++ compiler, MSYS Basic System, and Mingw basic Toolkit.

Then click next and install - this took me a while, if there are no error messages then you are set. My personal tip is turn off proxys when you do this because when I first installed with proxys on I got an error and had to reinstall.

Okay so now you are done with mingw setup. In order to open mingw open the start menu and search mingw, however do not drag the mingw file to desktop or anywhere else. This will break the program. If you want to open mingw search mingw in the start menu every time. If you know of a way to make a shortcut without breaking the program then let me know.

Next go to allegro.cc/files/ and if you downloaded mingw-get-inst-20120426 like me you will have MinGW 4.6.2 . Download MinGW 4.6.2 zip and extract the folder to your computer using winrar, izarc, or 7zip.

Copy the lib and include folder to C:\MinGW (Assuming you installed MinGW there).

Congratulations the library is successfully installed!

Here is a hello world program for allegro. (I got this hello world program from this persons website. I recommend going through all of his 2d game dev tutorials, they all compile using minGW even though he uses Microsoft visual studio 2010. http://fixbyproximity.com/2011/07/2d-game-dev-your-first-allegro-5-program/)

#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>

int main(void)
{
ALLEGRO_DISPLAY *display = NULL;

if(!al_init())
{
al_show_native_message_box(NULL, NULL, NULL,
"failed to initialize allegro!", NULL, NULL);
return -1;
}

display = al_create_display(640, 480);

if(!display)
{
al_show_native_message_box(NULL, NULL, NULL,
"failed to initialize allegro!", NULL, NULL);
return -1;
}

al_destroy_display(display);

return 0;
}

Make a folder in your c: directory called workspace, In that folder make another folder called allegro_hello, in that folder make a file called allegro_hello.cpp and copy the above source code into that file.

Start minGW. In order to go to c: drive type cd c: into the shell(command prompt). Now type cd workspace to get to your minGW workspace folder. Now type cd allegro_hello to get to your project folder. You may now type dir in order to view contents of the folder (there should be a file called allegro_hello.cpp)

Now you will compile your program. Here is a command you will use to compile your allegro programs with c++
COMMAND: g++ allegro_hello.cpp -o allegro_hello.exe -lallegro-5.0.6-monolith-md (In the future when you compile other programs replace allegro_hello with whatever the file name for your future projects is.) (I recomend saving command to a text document somewhere in your computer because it is hard to remember.)

(There will be 3 warnings but you can ignore this since this is only an example program.)
There will be a file in the folder called allegro_hello.exe. Type allegro_hello.exe to run the file and a window will pop up for a second.

Congratulations allegro is now set up correctly and you can program games or follow tutorials!

Any questions can be posted in the thread!

weapon_S
Member #7,859
October 2006
avatar

MSYS Basic System

That's not necessary.

Quote:

If you know of a way to make a shortcut without breaking the program then let me know.

I have this batch file. [1] This also removes the necessity to let MinGW "alter your system" i.e. add a path globally. You should make a shortcut to the batch file, not copy it.

@ECHO OFF
IF EXIST "%1" (
ECHO Passing a file to this script screws up the current working directory.
ECHO Aborting.
PAUSE
GOTO end
)
SET PATH=%CD%\C\MINGW\BIN;%PATH%;
SET MINGDIR=%CD%\C\MINGW
%windir%\system32\cmd.exe
:end
@ECHO ON

Any newbie who isn't afraid of a bigger challenge, I'd recommend to download Allegro's source and build it yourself, using the included help files. (You'll need to install CMAKE first...) This will give you the documentation, example programs, demo's with source, and of course Allegro's source. Especially the first two can be very handy to newbies. Although it will spice up linking a bit...
I.e. the provided command would become: g++ allegro_hello.cpp -o allegro_hello.exe -lallegro_native_dialog -lallegro, because all the modules have separate dll's unless you use 'monolith'.

References

  1. In my particular case the batch file is located in O:\Nerd\DEV. MinGW is in O:\Nerd\DEV\c\mingw
Karadoc ~~
Member #2,749
September 2002
avatar

I highly recommend getting minGW from here rather than from the minGW website. The distro I linked to always has the most up-to-date version, and includes some other useful libraries, such as Boost. And it also includes a batch file similar to the one weapon_S posted.

The only disadvantage is that the gcc version on that site is often ahead of latest version used for the prebuilt allegro binaries; so you have to compile allegro yourself. (For example, http://www.allegro.cc/files/ currently has 4.6.2 as the latest version of minGW; but nuwen.net currently has minGW v4.7.0.)

-----------

Go to: