[ S O L V E D ] ALLEGRO 5.0 UNDEFINED REFERENCE TO ANY LIBRARY

After installing allegro 5.0 on my UBUNTU 11.10 box I was getting the classic error: undefined reference to ..... Well, that's in the past now. For ANY kind of errors of this type it happens cause you are not linking to the correct .so files.Keep in mind that it is not enough to #include "allegro5/allegro.h" or any other header files.You hve to do 2 more things.


IN CODEBLOCKS for example, go to 
SETTINGS > COMPILER&DEBUGGER > LINKER SETTINGS.






IN THE LINK LIBRARIES SECTION YOU WILL HAVE TO ADD 1 LIBRARY PER #INCLUDE.
for example if you include "allegro5/allegro_image.h" you will need to add the liballegro_image.so 
to the link libraries section.


My installation of allegro5 was placed under /usr/lib/ as preffix when using cmake. On my case for not having any other related issues I added all the libraries that I will ever need.



/usr/lib/liballegro_dialog.so
/usr/lib/liballegro_color.so
/usr/lib/liballegro_audio.so
/usr/lib/liballegro_image.so
/usr/lib/liballegro_physfs.so
/usr/lib/liballegro.so
/usr/lib/liballegro_font.so
/usr/lib/liballegro_acodec.so
/usr/lib/liballegro_main.so
/usr/lib/liballegro_memfile.so
/usr/lib/liballegro_primitives.so
/usr/lib/liballegro_ttf.so




Also the compiler needs some parameters. In "Other linker options:" add 
`pkg-config --libs allegro-5.0`


Well, that's all for now and start programming games.


OH! one more thing, here is the whole code I was trying to run.

   #include <allegro5/allegro.h>  
   #include "allegro5/allegro_image.h"  
   #include <allegro5/allegro_primitives.h>  
   #include "allegro5/allegro_native_dialog.h"  
   int main()  
   {  
     #define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull  
     ALLEGRO_DISPLAY *display = NULL;  
     ALLEGRO_DISPLAY_MODE disp_data;  
     al_init();  
     al_init_image_addon();  
     al_init_primitives_addon();  
     al_set_new_display_flags(ALLEGRO_FULLSCREEN);  
     display = al_create_display(disp_data.width,disp_data.height);  
     al_rest(3);  
     al_destroy_display(display);  
     return 0;  
   }  





1 comment:

  1. in my dir usr/lib I could not find the libs!!

    ReplyDelete