Allegro5 with Eclipse on Ubuntu 11.10
Johannes Bergmark

I've some problems getting it to work. I've compiled and installed Allegro5 with no problems ie:
make -j8
sudo make install

As for in eclipse I've added the libs in:
Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Linker -> Libraries -> Library search path (-L)

which are:

`pkg-config --libs allegro-5.0 allegro_primitives-5.0 allegro_image-5.0 allegro_font-5.0 allegro_ttf-5.0`

The problem comes to that I get undefined reference errors of every allegro function call in the build-log.

I've tried to solve the problem och testing me through and googled after solutions, nothing worked.

1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_font.h> 5#include <allegro5/allegro_ttf.h> 6 7#include <math.h> 8#include<list> 9#include <iostream> 10using namespace std; 11 12int main(int argc, char **argv) 13{ 14 15 ALLEGRO_DISPLAY *display = NULL; 16 17 if(!al_init()) { 18 fprintf(stderr, "failed to initialize allegro!\n"); 19 return -1; 20 } 21 22 display = al_create_display(1280, 1024); 23 if(!display) { 24 fprintf(stderr, "failed to create display!\n"); 25 return -1; 26 } 27 28 //al_init_primitives_addon(); 29 al_init_image_addon(); 30 al_init_font_addon(); 31 al_init_ttf_addon(); 32 33 if(!al_install_keyboard()) return 0; 34 if(!al_install_mouse()) return 0; 35 al_set_system_mouse_cursor(display, ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT); 36 37 /* 38 while(!al_key_down(&kState, ALLEGRO_KEY_ESCAPE)) 39 { 40 al_clear_to_color(al_map_rgb(0,0,0)); 41 42 al_get_mouse_state(&mState); 43 44 45 mp.x = mState.x; 46 mp.y = mState.y; 47 al_get_keyboard_state(&kState); 48 49 50 al_flip_display(); 51 al_rest(0.01); 52 al_get_keyboard_state(&kState); 53 }//while 54 */ 55 56 al_rest(10.0); 57 58 al_destroy_display(display); 59 60 return 0; 61}

2*** Build of configuration Debug for project test *
3 4make all 5Building target: test 6Invoking: GCC C++ Linker 7g++ `pkg-config --libs allegro-5.0 allegro_primitives-5.0 allegro_image-5.0 allegro_font-5.0 allegro_ttf-5.0` -o"test" ./src/test.o 8./src/test.o: In function `main': 9/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:17: undefined reference to `al_install_system' 10/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:22: undefined reference to `al_create_display' 11/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:29: undefined reference to `al_init_image_addon' 12/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:30: undefined reference to `al_init_font_addon' 13/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:31: undefined reference to `al_init_ttf_addon' 14/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:33: undefined reference to `al_install_keyboard' 15/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:34: undefined reference to `al_install_mouse' 16/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:35: undefined reference to `al_set_system_mouse_cursor' 17/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:56: undefined reference to `al_rest' 18/media/sda3/Documents/eclipse_cpp_projects/test/Debug/../src/test.cpp:58: undefined reference to `al_destroy_display' 19collect2: ld returnerade avslutningsstatus 1 20make: *** [test] Fel 1

Arthur Kalliokoski

Maybe 'sudo ldconfig' might help? It updates the library locations or some such.

Trent Gamblin

Remove the -L from the pkg-config command.

Oh, I see eclipse did that because you put them in the wrong location. Put that command as extra libraries or whatever eclipse calls it.

Johannes Bergmark

I've already tried both solutions you guys/girls made. I've both removed -L and used ldconfig but it doesn't work. :(

Arthur Kalliokoski

I don't use any IDE's, but a command line that will successfully compile on Slackware is like

gcc -s -O2 -Wall t.c -o t -lallegro -lallegro_image -lallegro_ttf

Johannes Bergmark

Thanks Kallokoski!

This worked in terminal:
g++ -s -O2 -Wall test.cpp -o t -lallegro_primitives -lallegro_image -lallegro_ttf -lallegro_font -lallegro

But as for in Eclipse this turns out to be:
g++ -s -O2 -Wall -lallegro_primitives -lallegro_image -lallegro_ttf -lallegro_font -lallegro -o"test" ./src/test.o

which creates errors, there is something wrong with the automation here. I maybe will solve it...

Thread #608706. Printed from