|
How to compile a program using allegro |
2D_rob
Member #15,095
May 2013
|
Hello, I´m new to c programming and in the book i´m following I am to write a game which requires Allegro. I'm sitting on a windows 7 box and use mingw to compile my programs. I installed allegro "allegro-5.0.8-mingw-4.6.2" and mingw "mingw-get-inst-20120426.exe" and to verify that it´s working I found this code: I've been failing so many times trying to compile this code. this is what I write at the "MinGW Shell": /e/cbin/proj/allegro I´ve tried a lot of other combinations but I can´t compile this one? Any ideas? |
Gideon Weems
Member #3,925
October 2003
|
2D_rob
Member #15,095
May 2013
|
Thanks for the reply! Tried (in the "/e/cbin/proj/allegro" dir): Also this: Could I have missed some env variables? |
LennyLen
Member #5,313
December 2004
|
Go to your MinGW\lib folder and look for anything that starts with liballegro. I can't tell you exactly what it will be named for your version of A5 as I built from the WIP source. If you want you can post any files you find here, and we can tell you which one specifically to link to. edit: Just noticed from your last post... I'm guessing you have a liballegro-5.0.8-mt.a file. In which case, you link it with -lallegro-5.0.8-mt
|
2D_rob
Member #15,095
May 2013
|
This is what I have in the c:\mingw\lib $ ls liballegro* |
LennyLen
Member #5,313
December 2004
|
In that case then, yes, you want -lallegro-5.0.8-mt edit: I thought I'd add - this just links you to the base allegro library (mt as opposed to md means that the MS runtime libraries will be statically linked to your binary). Later on, if you start using the addons, you need to link these as well, or use the monolithic library, which contains al the addons in one.
|
2D_rob
Member #15,095
May 2013
|
Am I typing the gcc command wrong? The source file is located in e:\cbin\proj\allegro and is called "tst.c". When I run the command I am in that directory: Is there something wrong with this line? It shows these errors: |
LennyLen
Member #5,313
December 2004
|
If MinGW is set up correctly, you should only need to type: edit: Just for kicks, I downloaded the 5.0.8 binaries and tested it the same code and filenames you are using. The above command to gcc worked flawlessly for me.
|
2D_rob
Member #15,095
May 2013
|
Awesome! that did compile: $ tst.exe When I ran the program I got an error popup saying: I copied that dll from the location of the unzipped allegro bin folder to C:\MinGW\bin folder and ran the program again and I got no errors. So I´m guessing everything works fine. There were a lot of DLL's in the unzip folder. Should I copy all of those to the C:\minGW\bin folder? |
LennyLen
Member #5,313
December 2004
|
You can put them there. I prefer to copy them to each new project directory I make so that I know that all the files needed for the project (once it's built) are in one place.
|
2D_rob
Member #15,095
May 2013
|
Yeah that sounds smarter. Thanks for all the help. Now I can finally get to the actual coding. Cheers |
LennyLen
Member #5,313
December 2004
|
Some people might say it's a waste of space having multiple copies of the same dll lying around, and this is true to some extent, but I have around 4Tb of unused HDD space, so I don't care.
|
MrJBRPG
Member #15,096
May 2013
|
I have a similar problem, but I am using C++ as my main language using allegro 5.0.7 Before I tell you the details, I will give you specifics ////// Operating System: Mac OSX 10.6 Snow Leopard (Intel) I have attempted to do the following steps from the previous post, but I get a series of undefined errors: before using library calling g++ -Wall -Wextra -o allegro_start allegro_start.cpp I even tried for getting the main file to work g++ allegro_start.cpp -Wall -Wextra -lallegro-5.0.7-main -o allegro_start It's my first time using Allegro game engine too |
Trent Gamblin
Member #261
April 2000
|
Question: do you have Allegro installed? If so where is it installed? If not, you have to build it from source on a Mac. Then you can link it and allegro_main depending on how its build. Usually something like -lallegro -lallegro_main.
|
MrJBRPG
Member #15,096
May 2013
|
Thank you, those were the two commands needed to correctly compile the program , and I wonder what is the significance of -lallegro -lallegro_main? i.e g++ allegro_start.cpp -Wall -Wextra -lallegro -lallegro_main -o allegro_start |
Trent Gamblin
Member #261
April 2000
|
-lxyz tells the compiler to link with library xyz. The library has a bunch of functions and stuff just like a C source file and by linking it your program can use them.
|
Arthur Kalliokoski
Second in Command
February 2005
|
I might add that the stuff in libraries could be in source files in your project, but obviously linking all of Allegro each time you started a new project would be a pain. Libraries are kind of a systemwide collection of useful routines that are (hopefully) debugged, so you don't need the source for those functions in your project. For instance, I find the Mersenne random number generator to be quite useful, so I made a library for it and stuck it in with the other local (to this computer) libraries such as Allegro, and put a mersenne.h in the local includes. It does break projects you give to other people though, since they most likely don't have such a library, so you have to include the source and header again. They all watch too much MSNBC... they get ideas. |
|