3

What flags do I need to add to g++ in order to compile code using allegro 5? I tried

g++ allegro5test.cpp -o allegro5test `allegro-config --libs`

but that is not working. I'm using ubuntu 11.04. I installed allegro 5 using the instructions at http://wiki.allegro.cc/index.php?title=Install_Allegro5_From_SVN/Linux/Debian

I tried:

g++ allegro5test.cpp -o allegro5test `allegro-config --cflags --libs`

And it also gives a bunch of undefined errors, like: undefined reference to `al_install_system'

allegro-config --cflags --libs outputs:

-I/usr/local/include
-L/usr/local/lib -lalleg
John Stimac
  • 5,335
  • 8
  • 40
  • 60
  • Does `allegro5test.cpp` have the line `#include `? – Chris Frederick Jun 16 '11 at 19:35
  • possible duplicate of [Allegro in Ubuntu: undefined reference to `al_install_system'](http://stackoverflow.com/questions/5221981/allegro-in-ubuntu-undefined-reference-to-al-install-system) – trojanfoe Jun 16 '11 at 19:42
  • It's not a duplicate because that answer didn't solved the problem. That OP gave up and used a previous version of the library instead, and marked the answer as accepted because he is a nice person. This thread has the real answer. – karlphillip Jun 16 '11 at 20:22
  • 1
    The OP in that question marked the wrong answer. The answer I gave was correct. Allegro 5 uses pkg-config. – Matthew Jun 17 '11 at 06:42

2 Answers2

5

So you successfully installed allegro5 on your system from the SVN. One thing you should know is that this build doesn't come with allegro-config. If you have it on your system it means you have previously installed allegro4.

allegro5 brings many changes, including different initialization procedures, library and function names.

Here's a hello world application for new version:

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display = NULL;

   if(!al_init()) {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;
   }

   display = al_create_display(640, 480);
   if(!display) {
      fprintf(stderr, "failed to create display!\n");
      return -1;
   }

   al_clear_to_color(al_map_rgb(0,0,0));
   al_flip_display();
   al_rest(10.0);
   al_destroy_display(display);
   return 0;
}

Notice how the command to compile this application refers to another include directory and library names, which are different from the previous version of allegro:

g++ hello.cpp -o hello -I/usr/include/allegro5 -L/usr/lib -lallegro
karlphillip
  • 92,053
  • 36
  • 243
  • 426
3

Allegro 5 uses pkg-config.

pkg-config --libs allegro-5.0 allegro_image-5.0

And so on for each library you are using.

Matthew
  • 47,584
  • 11
  • 86
  • 98