Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Problem compiling "A4 code" using A5

This thread is locked; no one can reply to it. rss feed Print
Problem compiling "A4 code" using A5
xtheunknown0
Member #13,772
November 2011

Hello,

I "updated" the A4 code from a book to the point where running
gcc tankwar.c -o tankwar -I/usr/include/allegro5 -L/usr/lib -lalleg

yielded
tankwar.c: In function ‘main’:
tankwar.c:503: warning: assignment makes pointer from integer without a cast
/usr/bin/ld: cannot find -lalleg
collect2: ld returned 1 exit status

on Lucid Lynx.

So I went to the Allegro wiki for how to compile programs in 5.x.x and pasted
gcc tankwar.c -o tankwar -I/usr/include/allegro5 -L/usr/lib

But then my console "blew up" with:

Package allegro-5.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `allegro-5.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'allegro-5.0' found
tankwar.c: In function ‘drawtank’:
tankwar.c:20: warning: implicit declaration of function ‘al_draw_filled_rectangle’
tankwar.c: In function ‘explode’:
tankwar.c:139: warning: implicit declaration of function ‘rest’
tankwar.c: In function ‘updatebullet’:
tankwar.c:159: warning: implicit declaration of function ‘rect’
tankwar.c:180: warning: implicit declaration of function ‘getpixel’
tankwar.c:187: warning: implicit declaration of function ‘textprintf_ex’
tankwar.c: In function ‘score’:
tankwar.c:417: warning: implicit declaration of function ‘makecol’
tankwar.c: In function ‘main’:
tankwar.c:498: warning: implicit declaration of function ‘install_keyboard’
tankwar.c:499: warning: implicit declaration of function ‘install_timer’
tankwar.c:502: warning: implicit declaration of function ‘al_init_ttf_addon’
tankwar.c:503: warning: implicit declaration of function ‘al_load_ttf_font’
tankwar.c:503: warning: assignment makes pointer from integer without a cast
tankwar.c:536: warning: implicit declaration of function ‘keypressed’
tankwar.c:544: warning: implicit declaration of function ‘allegro_exit’
tankwar.c:496: warning: unused variable ‘display’
/tmp/cc2mF6FH.o: In function `drawtank':
tankwar.c:(.text+0x85): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0xb9): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0xf9): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0x12d): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0x16f): undefined reference to `al_draw_filled_rectangle'
/tmp/cc2mF6FH.o:tankwar.c:(.text+0x1a3): more undefined references to `al_draw_filled_rectangle' follow
/tmp/cc2mF6FH.o: In function `explode':
tankwar.c:(.text+0x615): undefined reference to `rest'
tankwar.c:(.text+0x653): undefined reference to `al_draw_filled_rectangle'
/tmp/cc2mF6FH.o: In function `updatebullet':
tankwar.c:(.text+0x6dd): undefined reference to `rect'
tankwar.c:(.text+0x81b): undefined reference to `rect'
tankwar.c:(.text+0x84d): undefined reference to `getpixel'
tankwar.c:(.text+0x8de): undefined reference to `textprintf_ex'
/tmp/cc2mF6FH.o: In function `checkpath':
tankwar.c:(.text+0x8fd): undefined reference to `getpixel'
tankwar.c:(.text+0x913): undefined reference to `getpixel'
tankwar.c:(.text+0x929): undefined reference to `getpixel'
/tmp/cc2mF6FH.o: In function `getinput':
tankwar.c:(.text+0x1095): undefined reference to `al_wait_for_event'
tankwar.c:(.text+0x11aa): undefined reference to `rest'
/tmp/cc2mF6FH.o: In function `score':
tankwar.c:(.text+0x1210): undefined reference to `makecol'
tankwar.c:(.text+0x1257): undefined reference to `textprintf_ex'
/tmp/cc2mF6FH.o: In function `setupdebris':
tankwar.c:(.text+0x1422): undefined reference to `makecol'
tankwar.c:(.text+0x1464): undefined reference to `al_draw_filled_rectangle'
/tmp/cc2mF6FH.o: In function `setupscreen':
tankwar.c:(.text+0x149c): undefined reference to `makecol'
tankwar.c:(.text+0x14de): undefined reference to `textprintf_ex'
tankwar.c:(.text+0x14fa): undefined reference to `makecol'
tankwar.c:(.text+0x1522): undefined reference to `rect'
tankwar.c:(.text+0x153e): undefined reference to `makecol'
tankwar.c:(.text+0x1566): undefined reference to `rect'
/tmp/cc2mF6FH.o: In function `main':
tankwar.c:(.text+0x158d): undefined reference to `al_install_system'
tankwar.c:(.text+0x1592): undefined reference to `install_keyboard'
tankwar.c:(.text+0x1597): undefined reference to `install_timer'
tankwar.c:(.text+0x15b0): undefined reference to `al_init_font_addon'
tankwar.c:(.text+0x15b5): undefined reference to `al_init_ttf_addon'
tankwar.c:(.text+0x15d1): undefined reference to `al_load_ttf_font'
tankwar.c:(.text+0x1604): undefined reference to `keypressed'
tankwar.c:(.text+0x1619): undefined reference to `rest'
tankwar.c:(.text+0x1627): undefined reference to `allegro_exit'
collect2: ld returned 1 exit status

Why doesn't my code compile?

TIA,
xtheunknown0

Matthew Leverton
Supreme Loser
January 1999
avatar

Package allegro-5.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `allegro-5.0.pc'
to the PKG_CONFIG_PATH environment variable

xtheunknown0
Member #13,772
November 2011

Apparently, no help.

I can give you a screenshot of this:
foo@foo:~/Documents$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
foo@foo:~/Documents$ gcc tankwar.c -o tankwar $(pkg-config --libs allegro-5.0)
Package allegro-5.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `allegro-5.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'allegro-5.0' found
tankwar.c: In function ‘main’:
tankwar.c:503: warning: assignment makes pointer from integer without a cast
/tmp/ccZrCMPA.o: In function `drawtank':
tankwar.c:(.text+0x85): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0xb9): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0xf9): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0x12d): undefined reference to `al_draw_filled_rectangle'
tankwar.c:(.text+0x16f): undefined reference to `al_draw_filled_rectangle'
/tmp/ccZrCMPA.o:tankwar.c:(.text+0x1a3): more undefined references to `al_draw_filled_rectangle' follow
/tmp/ccZrCMPA.o: In function `explode':
tankwar.c:(.text+0x615): undefined reference to `rest'
tankwar.c:(.text+0x653): undefined reference to `al_draw_filled_rectangle'
/tmp/ccZrCMPA.o: In function `updatebullet':
tankwar.c:(.text+0x6dd): undefined reference to `rect'
tankwar.c:(.text+0x81b): undefined reference to `rect'
tankwar.c:(.text+0x84d): undefined reference to `getpixel'
tankwar.c:(.text+0x8de): undefined reference to `textprintf_ex'
/tmp/ccZrCMPA.o: In function `checkpath':
tankwar.c:(.text+0x8fd): undefined reference to `getpixel'
tankwar.c:(.text+0x913): undefined reference to `getpixel'
tankwar.c:(.text+0x929): undefined reference to `getpixel'
/tmp/ccZrCMPA.o: In function `getinput':
tankwar.c:(.text+0x1095): undefined reference to `al_wait_for_event'
tankwar.c:(.text+0x11aa): undefined reference to `rest'
/tmp/ccZrCMPA.o: In function `score':
tankwar.c:(.text+0x1210): undefined reference to `makecol'
tankwar.c:(.text+0x1257): undefined reference to `textprintf_ex'
/tmp/ccZrCMPA.o: In function `setupdebris':
tankwar.c:(.text+0x1422): undefined reference to `makecol'
tankwar.c:(.text+0x1464): undefined reference to `al_draw_filled_rectangle'
/tmp/ccZrCMPA.o: In function `setupscreen':
tankwar.c:(.text+0x149c): undefined reference to `makecol'
tankwar.c:(.text+0x14de): undefined reference to `textprintf_ex'
tankwar.c:(.text+0x14fa): undefined reference to `makecol'
tankwar.c:(.text+0x1522): undefined reference to `rect'
tankwar.c:(.text+0x153e): undefined reference to `makecol'
tankwar.c:(.text+0x1566): undefined reference to `rect'
/tmp/ccZrCMPA.o: In function `main':
tankwar.c:(.text+0x158d): undefined reference to `al_install_system'
tankwar.c:(.text+0x1592): undefined reference to `install_keyboard'
tankwar.c:(.text+0x1597): undefined reference to `install_timer'
tankwar.c:(.text+0x15b0): undefined reference to `al_init_font_addon'
tankwar.c:(.text+0x15b5): undefined reference to `al_init_ttf_addon'
tankwar.c:(.text+0x15d1): undefined reference to `al_load_ttf_font'
tankwar.c:(.text+0x1604): undefined reference to `keypressed'
tankwar.c:(.text+0x1619): undefined reference to `rest'
tankwar.c:(.text+0x1627): undefined reference to `allegro_exit'
collect2: ld returned 1 exit status

Matthew Leverton
Supreme Loser
January 1999
avatar

Have you installed Allegro 5? Does the pc file exist in that location?

Note that many of the errors are references to Allegro 4 functions, so even when you get Allegro 5 working it still won't compile.

xtheunknown0
Member #13,772
November 2011

I think it's because I deleted the allegro-5.0 directory that svn created.

One thing that I can't apparently "fix" on my own is getpixel(). What is the "equivalent" in A5? I know that the answer to that may be pretty big, so I'll also ask: is it where for simple games (a main.c and a header) you declare a "screen" in the header and initialise it somewhere in main.c then start using it other functions? and how do I set up a screen?

BTW, so why was a "screen" argument removed from graphics primitives functions? I thought I could get away with using al_draw_[shape] functions but I need a "screen" for collision detection via getpixel...

Edgar Reynaldo
Member #8,592
May 2007
avatar

The drawing target (which will also be used with al_get_pixel) in Allegro 5 is part of a stored state. You set it with al_set_target_bitmap and then just call drawing functions as necessary, and they will all draw to the most recent drawing target that you have set with that function.

There is no 'screen' in A5, but semantically, the backbuffer is similar. You draw everything you want to display to it, and then call al_flip_display.

Also, you will probably want to rework your collision detection, because reading from video memory is slow (if you read from the backbuffer, or another video bitmap). Depends on how many pixels you need to read though.

xtheunknown0
Member #13,772
November 2011

I've got the code to the point where it compiles but it aborts due to loading a font.
I tried the code in the wiki about fonts (http://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Addons/Fonts) and it also

foo: /home/blah/allegro-5.0/addons/font/text.c:73: al_draw_ustr: Assertion `font' failed.

Why is this?

TIA,
xtheunknown0

Edgar Reynaldo
Member #8,592
May 2007
avatar

xtheunknown0
Member #13,772
November 2011

That is indeed the problem (returning zero). What do I do about it?

TIA,
xtheunknown0

Edgar Reynaldo
Member #8,592
May 2007
avatar

xtheunknown0
Member #13,772
November 2011

I think what wasn't clear from the start was the significance of having to load a font (, whereas my A4 book doesn't need to). Following from that is having an idea where A5 hunts for files.

So I read parts of the manual and I try
printf("%s\n", al_path_cstr(al_get_standard_path(ALLEGRO_RESOURCES_PATH), '/'));
font = al_load_ttf_font("DejaVuSans.ttf", 72, 0);

Now DejaVuSans.ttf is in my Documents/ where tankwar.c is (as well), so why is !font still "true"?

TIA,
xtheunknown0

Matthew Leverton
Supreme Loser
January 1999
avatar

It doesn't look anywhere for a font file, except for the exact spot you tell it to.

Your code does nothing but tries to load "DejaVuSans.ttf" from the current working directory. Your call to al_get_standard_path() is meaningless. Read Edgar's link and follow the instructions.

Edgar Reynaldo
Member #8,592
May 2007
avatar

So I read parts of the manual and I try

printf("%s\n", al_path_cstr(al_get_standard_path(ALLEGRO_RESOURCES_PATH), '/'));
font = al_load_ttf_font("DejaVuSans.ttf", 72, 0);

Now DejaVuSans.ttf is in my
Documents/ where tankwar.c is (as well), so why is !font still "true"?TIA,
xtheunknown0

Allegro doesn't search from anywhere except from the current working directory. That might not be the same as what is returned by al_get_standard_path(ALLEGRO_RESOURCES_PATH). To be sure, you have to set the current working directory yourself like the wiki showed you :

ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "resources");
al_change_directory(al_path_cstr(path, '/'));  // change the working directory
al_destroy_path(path);

Thomas Fjellstrom
Member #476
June 2000
avatar

ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "resources");
al_change_directory(al_path_cstr(path, '/'));  // change the working directory
al_destroy_path(path);

I suppose that is the simplest way. I don't know why but the way I think of first is:

ALLEGRO_PATH *res_path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(res_path, "resources");

ALLEGRO_PATH *file_path = al_clone_path(res_path);
al_set_path_filename(file_path, 'filename.ext');

ALLEGRO_FONT *font = al_load_font(al_path_cstr(file_path, '/'));
al_destroy_path(file_path);

In the end its the same, and the first is easier.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

xtheunknown0
Member #13,772
November 2011

Well, I think I've tried - please tell me if I haven't:

ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "resources");
al_change_directory(al_path_cstr(path, '/')); // change the working directory
font = al_load_ttf_font("DejaVuSans.ttf", 72, 0);
if (!font) {
printf("Error loading DejaVuSans.ttf.\n");
return 1;
}
al_destroy_path(path);

I still have the same problem, and there is now a resources/ (storing the ttf) in Documents/

What is it that I do not get?
TIA,
xtheunknown0

Edgar Reynaldo
Member #8,592
May 2007
avatar

Is your executable file in the Documents folder? If so, it should work. If it still does not work, link to the debugging version of allegro. Then your program will produce a file called allegro.log and you can look at it for clues as to why the font didn't load. You're sure you initialized both the font addon and the ttf addon before loading?

Code goes in <code>code goes here...</code> tags.

Thomas Fjellstrom
Member #476
June 2000
avatar

OH right, RESOURCES is actually the exe path on windows I think. You want ALLEGRO_USER_DOCUMENTS_PATH for your "My Documents" folder.

ALLEGRO_RESOURCES_PATH is actually the full path to the directory your executable is in. So if you use that, you put your data in the same dir as the exe.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

xtheunknown0
Member #13,772
November 2011

How do I create an allegro.log?

Sorry for being a nuisance.

Matthew Leverton
Supreme Loser
January 1999
avatar

What is it that I do not get?

al_change_directory(al_path_cstr(path, '/')); // change the working directory
printf("The path: %s\n", al_path_cstr(path, '/'));

Is the TTF there in that path that is displayed in your console window?

How do I create an allegro.log?

You have to link with the Allegro debug library and define something like ALLEGRO_DEBUG. But that's really not necessary. Debugging is simple: start with the obvious or simple and continue on until you find the problem. There are only a few reasons why it would fail:

  1. You didn't initialize the font and ttf addons, in that order.

  2. The TTF file isn't in that path specified.

  3. The file is corrupt.

  4. Allegro or the TTF library has a bug.

9 out of 9 times you'll get the problem figured out after the first and second points are corrected.

xtheunknown0
Member #13,772
November 2011

I believe I've tried the first two - I'm not sure how to help myself now.

https://sites.google.com/site/xtheunknown0/allegro

Edgar Reynaldo
Member #8,592
May 2007
avatar

Go to: