Dev C++ problem
Omikron

OK, so I just downloaded Dev C++ and installed it, in C:\Dev C++. Then I downloaded Allegro 3.9.35, and it's at C:\Dev C++\Allegro. When compiling, I get this error message:
allegro.h: No such file or directory
on this line:
#include "allegro.h"
What to do?

Omikron

Solved a part of it myself, just moved allegro.h, winalleg.h, linalleg.h and bealleg.h to C:\Dev C++\Include, and did this:
#include "allegro.h"
#include "winalleg.h"
But I get these errors:
C:\DEV-C_~1\INCLUDE\allegro.h:41: allegro\alconfig.h: No such file or directory
C:\DEV-C_~1\INCLUDE\allegro.h:2212: allegro\alinline.h: No such file or directory

Whyyyy?

Omikron

No need to reply on that one, got around it... New problem though :). On this line:
return (random() % (max-min+1)) + min;
Implicit declaration of function 'int random(...)'
And yes, I have included math.h.

Jeremias Raziel

random isn't a math.h function, it's a standard lib function (at least i think so)
For compiling allegro, you shouldn't use dev-c++ itself - at least that didn't work here.
You'll have to download the complete real mingw32 package, install it to c:\mingw32 and then compile allegro. It should work then, althought it didn't work in here for the cvs version, but the wip works fine...
Hopefully something of this chattering helps -:)
Ls

Omikron

Umm..... I already have MingW32 at C:\MingW32. Do I need to do anything with it, except from installing? (Already done)

Gabhonga

indeed:
C:\>cd mingw32
C:\MingW32\>cd allegro
C:\MingW32\Allegro\>fixming
(...blablabla...)
C:\MingW32\Allegro\>make
(...blablacompilinghaveabreakblablalba...)
and then there's finally relief

SystemDown

AFAIK, random() is not an ANSI C function.
You should be using rand() instead (stdlib function)
Also, you must seed the pseduo random number generator with srand() before you use rand() for the first time in your program (if you already know this, please ignore this next part).
The most common method of seeding is with the current time, as then it is unique every time you run it. You seed it with the current time with:
srand((unsigned int)time((time_t*)NULL));
If you're using C, those casts probably aren't necessary. You'll need to #include <time.h> though, or <ctime> if you're using C++.

SystemDown

oops.. it should've read "pseudo random number generator"

Omikron

So....I have included ctime (I'm using C++). Instead of this function...
int randnum(int min, int max)
{
// Returns an integer in the range from min
// to max
return ((random() % (max-min+1)) + min);
}
...I should have....what? Didn't really understand the srand part... Anyways, thanks all of you who replied.

SystemDown

Omikron, all I've done is replace random() with rand() in your function:
int randnum(int min, int max)
{
// Returns an integer in the range from min
// to max
return ((rand() % (max-min+1)) + min);
}
Before you use randnum(int min, int max) for the first time in your code, make a call to srand(), in the way that I described in my previous post. That's why u needed to #include <ctime>, because srand() is being seeded with the current time.
The purpose of using srand() (seeding) is to ensure that numbers returned by rand() are infact random, otherwise, every time you call rand(), it will return the same number!
I hope it makes more sense now.

Omikron

Thanks SystemDown, it almost works now :). The only problem is... I get hundreds of errors. For example:
undefined reference to `clear'
undefined reference to `makecol'
undefined reference to `_imp__font'
undefined reference to `_imp__screen'
undefined reference to `textout_centre'
undefined reference to `load_bitmap'
And sooo oooon............. Any ideas?

SystemDown

Well i'm glad you've got the random bit figured out now
:D
Your latest problem seems to be that you haven't linked in the Allegro library when you compiled your main program.
Link with the switch "-lalleg", eg:
g++ myProg.cpp -o myProg.exe -lalleg
Assuming your mingw32 path and everything is set up properly, and you've compiled Allegro, then this should solve all those "undefined reference" errors.

Omikron

Umm, where should the -lalleg part be?

Ivko

Ugh, hasn't anyone noticed that it should be #include <allegro.h> not #include "allegro.h"? :P

Ivko

-lalleg should be at the end of your command line.
quote:Link with the switch "-lalleg", eg:
g++ myProg.cpp -o myProg.exe -lalleg

Omikron

"allegro.h", <allegro.h>, no difference.
Anyway....my command line? I just press Ctrl+F9 and hope it will work.... Where should my command line be? And how do I set up my Mingw32 path? Thx.

vortex

There is a difference
Topic is:
#include <allegro.h>
VS.
#include "allegro.h"
#include <allegro.h>
It searches allegro.h in the standard include directory (ex. "c:\mingw32\include")
#include "allegro.h"
It searches allegro.h in current project directory (ex. "c:\mingw32\projects\001\src")
Those two should work like that (I don't know how they behave under mingw32...).
Topic no 2.
The mingw32 path is set by typing
SET PATH=%PATH%;C:\MINGW32\BIN
into your autoexec.bat
you can also add these two lines if you are using Bison:
SET BISON_SIMPLE=C:\MING32\SHARE\BISON.SIMPLE
SET BISON_HAIRY=C:\MINGW32\SHARE\BISON.HAIRY
where c:\mingw32 is your MingW32 directory

Cage

I'm about to start using Dev-C++ and these problems sound troubling... (right now I use DJGPP) I think Omikron's problem, there should probably be a menu option for "include" or "library include" or something (there is in DJGPP) you should just (okay, this is from DJGPP, please excuse me if it isn't quite right, I'll have Dev-C++ tomorrow) find one of the boxes and type in "alleg" without the quotes and check the box next to it or something... i'll have a detailed runthrough for you tomorrow.

SystemDown

Sorry Omikron.. I thought you were using plain mingw32 and not Dev-C++.
I can't help you with the latter because I don't use it.. but I'm sure quite a few people on this board can step you through the setup process for Dev-C++.

snake eyes

I am using dev-c++ right now myself. The only version of allegro I ever managed to get to compile is 3.9.3.2. If you manage to get 3.9.3.5 compiled successfully with it I woould appreciate you letting me know how you did it!
As for linking with allegro you click the notepad with the pencil above it (farthest right on the toolbar) and u should see a button about adding libs....

snake eyes

Omikron

First of all, thanks everyone who replied!
vortex: Where should SET PATH=%PATH%;C:\MINGW32\BIN in autoexec.bat be? Should I delete all DJGPP stuff? My autoexec.bat currently looks like this:
SET BLASTER=A220 I2 D3 H7 P330 T6
SET CTSYN=C:\WINDOWS
C:\PROGRAM\CREATIVE\SBLIVE\DOSDRV\SBEINIT.COM
Rem TShoot:
set DJGPP=C:\DJGPP\DJGPP.ENV
Rem TShoot:
set PATH=C:\DJGPP\BIN;%PATH%
mode con codepage prepare=((850) C:\WINDOWS\COMMAND\ega.cpi)
mode con codepage select=850
keyb sv,,C:\WINDOWS\COMMAND\keyboard.sys
Thanks.

Cage

Okay, Omikron, you should add this line to the end of your autoexec.bat file:
set path=c:\dev-c++\include;c:\dev-c++\lib;c:\dev-c++\allegro

just substitute whatever directory you installed into for dev-c++. But I have a problem:
I did all this, and linked with the -lalleg option, and I get this error when I compile/link it:
g++: -lalleg: linker input file unused since linking not done

It pops up in a little window. Is there anyone out there who managed to properly install allegro for Dev-C++ and if so, how did you do it? And Omikron, I don't think you have to delete all your DJGPP stuff. PLEASE HELP!!!!!!

Thread #156641. Printed from Allegro.cc