Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Allegro5 with Eclipse on Ubuntu 11.10

This thread is locked; no one can reply to it. rss feed Print
Allegro5 with Eclipse on Ubuntu 11.10
Johannes Bergmark
Member #4,867
July 2004
avatar

I've some problems getting it to work. I've compiled and installed Allegro5 with no problems ie:
ccmake -DCMAKE_INSTALL_PREFIX=/usr ..
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.

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

#SelectExpand
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

"There are no Mines for the Sword." --?

"Det finns inga Minor för Svärdet." --?

Arthur Kalliokoski
Second in Command
February 2005
avatar

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

“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

Trent Gamblin
Member #261
April 2000
avatar

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
Member #4,867
July 2004
avatar

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

"There are no Mines for the Sword." --?

"Det finns inga Minor för Svärdet." --?

Arthur Kalliokoski
Second in Command
February 2005
avatar

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

“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

Johannes Bergmark
Member #4,867
July 2004
avatar

Thanks Kallokoski!

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

Edit:
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...

"There are no Mines for the Sword." --?

"Det finns inga Minor för Svärdet." --?

Go to: