Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Setting up Allegro 5 with Code::Blocks, MinGW

This thread is locked; no one can reply to it. rss feed Print
Setting up Allegro 5 with Code::Blocks, MinGW
chessguy
Member #14,033
February 2012

Hello all. I have recently learned some C++ (most of it), and now I want to practice. However, I want to practice making games as well, and using graphics, not to mention actually being able to use keyboard input. So far, I have made several things... but text is limited, I cannot use the keyboard, and the ebst visuals I could get on the console were with a "guess that shape!" game, featuring colored shapes. Long story, it was for practice...

Anyway, I am using Code::Blocks and MinGW. I am not really certain how to set up allegro, though. This is my first time setting up a library. I want to link to it statically. Currently, I was trying to find the article you have for this on the wiki with allegro 5. I found all the files in the lib folde,r and put them in order, except instead of 5.0.4 as in the pictures it is 5.0.5. Anyway, after this, it said something about lib folders in MinGW. Some were there, some weren't.

Also, it also goes into global compiler and debubber settings > search directories. Then, compiler tab. I can find the allegro 5 (the folder name is a bit long, something about MinGw4.5.2 or something in there), and the include folder. However, it does not ask if it is a relative path, although in the picture it suggests it did, so I may have done something wrong.

Any ideas how to fix these issues and get it working?

Also - with what I have so far, I #included <iostream>. It said ti could not find iostream, which is odd. I think it was something I did in the build options (under project tab) but I am not sure. Iostream still includes fine in other projects.

Thanks.

Trent Gamblin
Member #261
April 2000
avatar

iostream not including sounds like it's a C project and not C++. The other issues, I don't know about.

AMCerasoli
Member #11,955
May 2010
avatar

To solve the problem about iostream, save your files as .cpp instead of .c (myFile.cpp).

chessguy said:

Anyway, after this, it said something about lib folders in MinGW. Some were there, some weren't.

The folders you need when making a static link using the pre-built binaries are: "lib" and "include".

Quote:

However, it does not ask if it is a relative path, although in the picture it suggests it did, so I may have done something wrong.

No, you didn't anything wrong, the problem is I don't know why I used the global options for the linking process and the project options for the includes... ::) My bad. You can put it in the global properties, it's fine.

Quote:

Any ideas how to fix these issues and get it working?

Tells us what errors are you getting.

chessguy
Member #14,033
February 2012

First, is i a C++ file/project, and is .ccp. What I meant was, it said it couldn't find the file or directory - it wasn't a red error like the others, though, so I don't think it was quite the same problem. It works fine in all my other projects, so I am guessing my library including may have done something.

AS per the lib folder in MinGW, I meant, er, I couldn't find some of the libraries. This was when I was linking to libraries in project build options/linker. Not the global compiler settings, yet.

Did I state that wrong? In the project build options, I was including the libraries themselves - like, liballegro-audio-mt.a, or something similar, etc. Got tha tpart done, but it also said linkng to libraries that were with MinGw, in the lib folder, and I could not find some of them. That is, the .a files.

Now, in the global compiler settings, it says (also in search directories/compiler), to find the include folder in Allegro, if I recall correctly. I found it, but it did not ask for a relative path, though I thought I did it the same as in the example.

Well, right now I am just trying to seet it up for a project. As of right now, though, it cannot find any of the #includes for the sample code given on the wiki, so I figure I have not done it right yet. So, I am trying to figureo ut how to do all the linking parts right.

I thought learning C++ would be hard, but I have to admit my quests to get an external library working seems to not be so simple... hm :)

AMCerasoli
Member #11,955
May 2010
avatar

chessguy said:

What I meant was, it said it couldn't find the file or directory - it wasn't a red error like the others, though, so I don't think it was quite the same problem. It works fine in all my other projects, so I am guessing my library including may have done something.

I don't understand very well what you're saying, but in case you still having the problem about Code::Blocks telling you that it can't find the iostream library, as I told you before, when you create a new empty project, or when you create a new console project you need to make sure that it's a C++ project.

If you create a console project the wizard automatically ask you if it's going to be C or C++. But when you create a new empty project you need to create a file, and put the ".cpp" extension at the end, otherwise if you don't put anything Code::Blocks automatically put a ".c" extension, and after that, it will search libraries in the "C paths" and of course it won't be able to find the iostream library.

Quote:

AS per the lib folder in MinGW, I meant, er, I couldn't find some of the libraries. This was when I was linking to libraries in project build options/linker. Not the global compiler settings, yet.

If you couldn't find some of the libraries there was probably a problem when downloading the pre-built binaries. It's pretty weird because when a .zip file doesn't download correctly becomes automatically corrupt and you can't see anything in it.

Quote:

Did I state that wrong? In the project build options, I was including the libraries themselves - like, liballegro-audio-mt.a,

You can use both to link your libraries: "Project -> Build Options" or "Settings -> Compiler and Debugger". You can also use both to tell C::B where to find the include files, the unique difference is that with "Settings -> Compiler and Debugger" you set it once, and each time you create a new project it's going to be ready to use, instead with "Project -> Build Options", once you create a new project you'll need to do the whole process again.

Quote:

I found it, but it did not ask for a relative path, though I thought I did it the same as in the example.

Yes, that is because there is a typo in that article. The linkage process and the include process should be done in the same place, either in the Settings options or in the Project options. The problem with that article is that the linkage process is done in the Settings options and the include directories are set in the project options. The only way C::B would ask you about relative paths is if you use the Project options and as you can see the wiki isn't using the Project option but the Setting options, for that reason in the wiki there is nothing about relative paths.

Quote:

Well, right now I am just trying to seet it up for a project.

If it's just for one project and you don't intend to use Allegro anymore, then use the Project options (Project -> Build Options). Remember that once you delete that project, or create a new project you'll need to do the entire process again.

Quote:

As of right now, though, it cannot find any of the #includes for the sample code given on the wiki, so I figure I have not done it right yet. So, I am trying to figureo ut how to do all the linking parts right.

I think you downloaded the Source Code instead of the pre-built binaries. Go to the file section here at allegro.cc and download the binaries, not the Source Code. Otherwise, I have no idea why you have an incomplete set of the libraries.

chessguy
Member #14,033
February 2012

It was a .cpp project, yes. IT was just, after my attempt in project build options, it said that iostream directory coul dnot be found, but it wasn'r red like the other errors. A warning? Not sure. IT does not seem to occur anymore, though, and works fine for all other projects.

Let be clarify. I found all the Allegro files I needed in the lib folder. However, it said you also needed some libraries from MinGW/lib, and I did not find some of them. You are saying that might be corrupt?

Oh. What I meant was, I am trying to just get one with th elibraries linked correctly so I can try to make something. I do plan to be using Allegro as my only API for a bit, till I hav esome more practice at least but probably into the future. It would be gereat if I could do i via global compiler settings, yes.

If I was going to do it soley using the global compiler settings, what should I try, and is that all I need to do?

AMCerasoli
Member #11,955
May 2010
avatar

chessguy said:

However, it said you also needed some libraries from MinGW/lib, and I did not find some of them. You are saying that might be corrupt?

Sorry man, my bad, I was very distracted when I answered you. I didn't notice you was talking about the lib folder inside MinGW, that is event weirder, but yhea, I have experienced in the past, when for first time downloaded MinGW that some files were missing, my connection is very slow so for that reason I already knew was a problem with my connection. I reinstalled it, and it worked fine. I have never heard someone around here having problems with missing MinGW libraries, so try reinstalled to see what happens. Are you using the MinGW installer, isn't it?

Quote:

If I was going to do it soley using the global compiler settings, what should I try, and is that all I need to do?

Yhea, if you're going to be using Allegro a lot, you should definitively configure everything in the global settings, you can change it in the future anyways. Do all what the wiki says to do, but only in the global settings, which is basically link the libraries and tell C::B where to find the includes, and that's it.

chessguy
Member #14,033
February 2012

Yes. The most recent, I think, but I am not sure. Stable version, that is, although I am not sur e if they release unstable versions like most others do. You think I should try to re-download and overwrite what I have currently?

On second thought... I installed Code::Blocks with MinGW as directed from the Code::Blocks site. Think that was my problem?

So you are saying, in global compiler settings, in linker settingsd do the same thing I would for in the project build options, and in search directiories/compiler do the Allegro include folder?

AMCerasoli
Member #11,955
May 2010
avatar

chessguy said:

Yes. The most recent, I think, but I am not sure. Stable version, that is, although I am not sur e if they release unstable versions like most others do. You think I should try to re-download and overwrite what I have currently?

If you're using the MinGW installer you have the last version of MinGW (4.6.1), if it is stable or not I have no idea neither. :P

Quote:

On second thought... I installed Code::Blocks with MinGW as directed from the Code::Blocks site. Think that was my problem?

Uh?... Did You install C::B with MinGW and then also installed another MinGW apart using the MinGW installer? WTF :o. You don't need to do that, I don't know which version of MinGW comes with C::B because I have never downloaded C::B with MinGW, but I'm completely sure that is not the problem... I don't know why you can't find those libraries... They're pretty old, nothing new.

You can't find either of them or some of them? if it's just some of them, which are?

Quote:

So you are saying, in global compiler settings, in linker settingsd do the same thing I would for in the project build options, and in search directiories/compiler do the Allegro include folder?

Yep.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

LennyLen
Member #5,313
December 2004
avatar

If you compile with gcc, it won't find iostream, but with g++ it will

Although, since he's using C::B, it's the type of project that you create that determines whether gcc or g++ gets used.

The problem could be caused by an incomplete MinGW installation, or also by the toolchain settings in Code::Blocks not being set correctly.

chessguy
Member #14,033
February 2012

No worries about iostream anymore, I don't think it is a problem.

On the Code BLocks site, when I first downloaded it, I did it with the MinGW it includes with it, not directly from the MinGW site at any time, so I am not sure how recent of a version it is.

I found some of th e libraries in MinGW/lib, but not others - the first, for instance. Seeing as how I a m missing a few and they wouldn't be in correct order, this is probably a problem. That is where I am stuck right now. I can set up the global compiler settings - search directories - compiler - Allegro/include part, and I can do all the libraries in linker settings - include libraries, for the Allegro ones, but am missing some of the MinGW ones. I haven't done anything with the other linker options thing that is on the right, though. (of same page).

Eh... this is frustrating.

Ok. So, I am linking statically.

I found all the correct libraries in Allegro folder (lib). In MinGW/lib, I found all the ones listed except the libgdiplus.a one. Nowhere to be found, searching, looking... does not seem to exists. Now, all of this in global compiler settings, in linker options, I included all those libraries (allegro then MinGW), and pasted this into other linker poptions

-lgcc_eh
-static-libgcc
-static-libstdc++

Next, I went to search directiories, then compiler, and included Allegro/include.

Trying to run the test code (with static link), I get the error:

Cannot find -lgcc_eh

I I take this out (in the other linke roptions, I get:

cannot find -luser32

Although I can see that is a library I included, from MingGW/lib.

Any ideas?

AMCerasoli
Member #11,955
May 2010
avatar

Quote:

Any ideas?

Yes... I'll need to make a videotutorial. :-/:-X

chessguy said:

I found all the ones listed except the libgdiplus.a one.

Sorry man, but to make a static link, you need to link to all the libraries. I don't know which version of MinGW comes with C::B, but I can't believe didn't come with libgdiplus.a. But if you say so, then you should use the MinGW installer as the wiki tutorial says and forget about the MinGW that comes with C::B.

Quote:

I I take this out (in the other linke roptions, I get: cannot find -luser32 Although I can see that is a library I included, from MingGW/lib.

Probably you haven't place the libraries in the correct order, check out that. But without libgdiplus.a won't work.

chessguy
Member #14,033
February 2012

I will try to re-download minGW from the normal site. Most recent.

When I installed code blocks, though, with MinGW, it didn't go through with the console listing things and.. tkaing so long. Which option do you pick, in the downloader? Also, I don't think I need to set an enviorment variabkle, do I?

How can you swap files in a folder? I noticed that libuuid.a was near the end, yet ti was the second one. Odd, though, because when I did the Allegro fles they went into a folder in the order I put them in.

I don't know. I am certain I did not move or delete it, though.

IS setting up external libraries usually this difficult, or am I just terrible at it?

LennyLen
Member #5,313
December 2004
avatar

chessguy said:

Also, I don't think I need to set an enviorment variabkle, do I?

Yes, you do.

Quote:

Which option do you pick, in the downloader?

Sorry, can't help you there, I always download the individual packages rather than use the installer.

Quote:

How can you swap files in a folder? I noticed that libuuid.a was near the end, yet ti was the second one. Odd, though, because when I did the Allegro fles they went into a folder in the order I put them in.

Right-click anywhere inside the directory in explorer, and in the menu that pops up, select Sort By, then however you want them sorted.

Quote:

IS setting up external libraries usually this difficult, or am I just terrible at it?

A lot of the problems you seem to have aren't even related to Allegro. Allegro's installation is fairly typical, and if you have things set up correctly can be accomplished with three simple commands from the console. There are definitely libraries that are more difficult to set up.

AMCerasoli
Member #11,955
May 2010
avatar

chessguy said:

Which option do you pick, in the downloader?

I can't remember, I was trying to look at the wiki but for some reason is down, maybe later. But just download that that say something like stable version or something.

chessguy said:

I need to set an enviorment variabkle, do I?

LennyLen said:

Yes, you do.

No he doesn't. The environment variables are necessary only when building/compiling Allegro.

Quote:

How can you swap files in a folder? I noticed that libuuid.a was near the end, yet ti was the second one.

The files order in the folder doesn't matter. They need to be in order just inside C::B.

Quote:

IS setting up external libraries usually this difficult, or am I just terrible at it?

You're not terrible at it... You're just a newbie, we all passed through the same. ;)

chessguy
Member #14,033
February 2012

On the envioroment variable - to my understanding, that is when you compile things via command line (or prompt). As I am using Code::Blocks for MinGw usage, however, I figured it wasn't - hasn't been thus far, but who knows? That is how the wiki was on installing MinGw, but I don't beleive that was attached to Code::Blocks, and so it'd be as if it were used without an IDE, for example.

AS per the installer - well, I think there are two options. One is... something about pre-made catalogs? And I think the other was search for most recent ones. I beleive the article on installing MinGW, for by itself, uses the later. I don't know the difference.

As per swapping folders - yes, I have used the sorting recently - lists, for example, were useful in picking out whic libraries were needed.
They don't need to be in order outside, but I figured it'd be easier to put it into a folder because then I can select all the ones I need withut searching AND have them in order, as I cannot really memorize it.

Now, say I have them already in a folder. How could "I make one switch places with another? When I try it did not seem to work. On second though, if you move one onto another, it inserts it at tha tpoint (before the other file). If you place it after them all... well, that is where it goes. Mabye my problem was the list. Not sure.

As per setting up external libraries... which problems don't relate? Iostream never threw an error (although I am still not sure quite what that meant, as it wasn't a red error like the others), and once I tried doing this, it did, so I figured something is relative. Second, well, I think finding that lat library is my current problem, which is relative. The folder swapping - not so much, but.. never mind.

I hope I do learn, then. So far it seems like you set up that libraries include folder with - well, with the include folder, and then link libraries. Hopefully they provide which order to put them in, though. I have vo idea what other linker options does.

You'd think, when tryign to learn PRogramming, the problem would be in the programming. Hm.

While we are on this, I have had a thought since I considered trying to make non-consoel stuff. How do you check if somethign is clicked on? I can think of some math ways to do this for some stuff, but for others, it'd be a nightmare. Is there some sort of graphics/click on event?

AMCerasoli
Member #11,955
May 2010
avatar

chessguy said:

I beleive the article on installing MinGW, for by itself, uses the later. I don't know the difference.

Me neither, but since has been proved that that one works, just download that... ;D The wiki says to set up the environment variable just to check if everything works fine, but they're not needed when using the pre-built binaries of Allegro.

Quote:

While we are on this, I have had a thought since I considered trying to make non-consoel stuff. How do you check if somethign is clicked on? I can think of some math ways to do this for some stuff, but for others, it'd be a nightmare. Is there some sort of graphics/click on event?

Uff, that is another thread man, and it's about game programming itself. A hint about the button and the clicking stuff would be collision detection.

chessguy
Member #14,033
February 2012

I think I made progress.

Ok. So, I re-downloaded MinGW. Although perhaps I should have gotten rid of the old version first... not sure. Anyhow, I found the missing library, and followed everything as the wiki has it - except in global compiler settings. IT gives me a different error now - first, an error, something about WinMain16 or something similar. Oddly, though, it said on line 73 - my program, also exactly what is on the wiki, was... only ten lines. Or nine. I think the tenth was blank.

It first seemignly thorws a warning and then an error afterword.

It also threw a warning (not sure if it was an error) regarding the kernal file. Er, the kernal32.a one. Or is it libkernal? I don't remember. Ah, it is libkernal. Anyway, it just thew an error like "warning:" and then the filename to the kernal library. Before I got these error messages, there was a popup which said ld.exe stopped working, failed, etc. (you know, when it is like "do you want to report this to microsoft?"). I think ld.exe was the linker, is it not? Not sure. Anyway, that popped up, and then I get that warning.

I don't recall why, but I debugged it again after, see if it woul d occur again. Now, half the time I try it, it display ythe normal lokoing messages - you know, amke the file in the debug folder of your project, the debugger start-up process, the debugger version - adn then it seemignyl hangs. Doesn't open the ocnsole, does not stop - I had to stop the debugger manually. Some times, it says build is up to date and stops there. Other times, now, it has ld.exe fail, and displays the warnings, but now I don't get any WinMain16.

Oh - on that build up to date part - it is... "target is up to date. nothing to be done." It also poips up "build failed".

I tried taking out:

-lgcc_eh
-static-libgcc
-static-libstdc++

Seeing if the version of MinGW I has was the issue (on the wiki it notes this). IT seemignly makes no difference, so odds are I either don't need it or it never reaches it.

I checked the file order in the including libraries part, but it seems fine. I have libkernal32.a after all the allegro libraries and the libgdiplus (the missing library which I now have), and libuuid.a.

Ideas?

EDIT: Still stuck on this. I also tried the ever-powerful Google, but alas I cannot seem to find quite the same problem.

AMCerasoli
Member #11,955
May 2010
avatar

Man, I don't know about those errors... You should paste here the complete error message to see if we can figure it out.

Go to: