Allegro on Ubuntu: undefined reference to `al_install_system '

I tried to install the Allegro library today. I have the same experience in C ++, but it seems I don't have such things to do. I compiled Allegro 5.0 from the source and put it in / usr / lib / gcc / i 486-linux-gnu / 4.4 / include / allegro5. But when I try to compile my code, it looks like this:

    > g++ test2.cc -o test2
/home/chris/Desktop/c++/test2/.objs/main.o||In function `main':|
main.cpp:(.text+0x22)||undefined reference to `al_install_system'|
main.cpp:(.text+0x3e)||undefined reference to `al_create_display'|
main.cpp:(.text+0x6b)||undefined reference to `al_map_rgb'|
main.cpp:(.text+0x8e)||undefined reference to `al_clear_to_color'|
main.cpp:(.text+0x93)||undefined reference to `al_flip_display'|
main.cpp:(.text+0xa1)||undefined reference to `al_rest'|
main.cpp:(.text+0xa9)||undefined reference to `al_destroy_display'|
||=== Build finished: 7 errors, 0 warnings ===|

The code I'm using is:

#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;
}

allegro-config --libsreturns nothing. At first I had Allegro, but it did not work either.

+2
source share
2 answers

You need to link to Allegro libraries, but you don't seem to be doing this.

allegro-config --libs returns nothing.

There is part of your problem. You can usually add it to your command line, for example:

g++ `allegro-config --libs` test2.cc -o test2

On my system (Ubuntu 10.10) it gives the following:

$ allegro-config --libs
-L/usr/lib -Wl,-Bsymbolic-functions -lalleg-4.2.2

allegro-config? , ?

+1

Allegro 5 pkg-config.

gcc foo.c -o foo $(pkg-config --libs allegro-5.0)

, :

gcc foo.c -o foo $(pkg-config --libs allegro-5.0 allegro_image-5.0)
+21

All Articles