Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Compilation error: allegro.h not found

This thread is locked; no one can reply to it. rss feed Print
Compilation error: allegro.h not found
Wintermond
Member #11,231
August 2009

Hello

I'm trying to compile my first allegro program. I thought the installation worked (according to the readme-file in allegro-4.9.12.zip i did: cmake, make, make install. all three commands gave no error messages).

When doing:
gcc hello.cpp

The compiler answers:
hello.cpp:1:21: error: allegro.h: No such file or directory

Do I need to add some parameters to the gcc-command (specify where the header file is)? The examples (which came in the allegro zip-file) are compiled - and working. So I guess, it can't be too difficult to compile my own...

Thanks for your help!

LennyLen
Member #5,313
December 2004
avatar

Try #include <allegro5/allegro.h> or #include <allegro5/allegro5.h>

Evert
Member #794
November 2000
avatar

Are you sure 4.9.12 is what you want? That's the unstable development branch for the next version of Allegro.
Most information you can find online and that you may be familiar with is for the old Allegro 4 (and earlier), which is nothing like the new Allegro. Just so you know.

Wintermond
Member #11,231
August 2009

Thank you, LennyLen! Unfortunately I've got another problem now. I don't know if that matters, but I'm running Mac OS X 10.5 on a G5.

My code:

#include <allegro5/allegro.h>
int main(int argc, char* argv[]) {
        al_init();
        return 0;
}
END_OF_MAIN()

Compilers opinion (started with: gcc hello.cpp):

Undefined symbols:
"___gxx_personality_v0", referenced from:
___gxx_personality_v0$non_lazy_ptr in cceozQSp.o
"_main", referenced from:
start in crt1.10.5.o
"_al_install_system", referenced from:
_mangled_main(int, char**)in cceozQSp.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Arthur Kalliokoski
Second in Command
February 2005
avatar

Maybe you should try g++ instead of gcc?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Wintermond
Member #11,231
August 2009

The response of g++ is similar:

Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
"_al_install_system", referenced from:
_mangled_main(int, char**)in ccMAS6NT.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Arthur Kalliokoski
Second in Command
February 2005
avatar

You need to put END_OF_MAIN() after the, well, end of main().

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Wintermond
Member #11,231
August 2009

I did:

#include <allegro5/allegro.h>
int main(int argc, char* argv[]) {
        al_init();
        return 0;
}
END_OF_MAIN()

Matthew Leverton
Supreme Loser
January 1999
avatar

You need to link with `pkg-config allegro-4.9 --libs` or the OS X equivalent.

Evert
Member #794
November 2000
avatar

You need to link with `pkg-config allegro-4.9 --libs` or the OS X equivalent.

It's that in OS X.

Arthur Kalliokoski
Second in Command
February 2005
avatar

tsk I just tried compiling an a5 program myself (allegro-4.9.12/examples/ex_acodec.c) and it took me 15 minutes of poking around to stumble across
gcc -s -O2 -Wall ex_acodec.c -o acodec `allegro5-config --libs` -lkcm_audio-4.9.12 -la5_acodec-4.9.12
to get it to find all necessary libs.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Matthew Leverton
Supreme Loser
January 1999
avatar

`pkg-config allegro-4.9 kcm_audio-4.9 a5_acodec-4.9 --libs`

Arthur Kalliokoski
Second in Command
February 2005
avatar

So if I fiddle around with nm(1) long enough and sort which functions are in which libraries I can add to the docs?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Evert
Member #794
November 2000
avatar

So if I fiddle around with nm(1) long enough and sort which functions are in which libraries I can add to the docs?

The documentation already lists which functions go into which addon (or rather, which addon contains which function) - although that may be a recent addition. It should probably also give you the linker option or the name of the library to link with to get that particular addon.
Yes, that's a part of the documentation that should be updated. What's really missing right now is a "Using Allegro" type section that gives you the bird's-eye overview.

In your particular example, "ex_acodec" should be a hint that you need to link at least with a5_acodec (otherwise a glance at the source should tell you this), which depends on kcm_audio (pkg-config would pull that dependency in automatically, I think). So it shouldn't be that hard to figure out.
But again, a "Using Allegro" section is lacking at the moment.

Matthew Leverton
Supreme Loser
January 1999
avatar

I don't think it does. e.g., the font section has both font addons merged together (as it should). But it's not hard to figure out.

Each function should ultimately be marked with header file, library file, and in which Allegro version it first appeared (beginning with 5.0.0).

Wintermond
Member #11,231
August 2009

Thank you all! Just had to download pkg-config. My do-nothing-allegro-program compiles now, using:

g++ `pkg-config allegro-4.9 --libs` hello.cpp

To Evert (asking if I'm sure, that 4.9.12 is what I want): No actually I was/am not sure. I just downloaded the newest version from Sourceforge and tried to follow the instructions in the readme file. Since I have a working environment now, I think (at least I hope) I will be fine...

Thanks again to everyone!

Peter Wang
Member #23
April 2000

pkg-config pulls in dependencies, so you only actually need to list the top one, e.g. `pkg-config --libs a5_acodec-4.9`

Evert
Member #794
November 2000
avatar

No actually I was/am not sure. I just downloaded the newest version from Sourceforge and tried to follow the instructions in the readme file. Since I have a working environment now, I think (at least I hope) I will be fine...

Ok. In that case, I applaud your determination and encourage you to ask lots of questions and give loads of feedback on the library and the documentation. The reason is that the library (and the API) are not stable yet and still subject to change , so if something is not designed well, it can still be fixed now.
The downside is that the documentation is incomplete and somewhat rough compared to Allegro 4's documentation and that subsequent releases may not be compatible: be prepared for having to change your code after you update to the next version of Allegro.

Go to: