Thread: Allegro 5.0 library woes T_T

  1. #1
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665

    Allegro 5.0 library woes T_T

    Hello All,

    I'm on Arch Linux and if you don't know about Arch, it has a wicked awesome package manager so all I did was type "pacman -S allegro" and voila, allegro was installed.

    So, this code works :
    Code:
       ALLEGRO_DISPLAY *display = NULL;
    
    
       if (!al_init()) {
    
    
          fprintf(stderr, "failed to initialize allegro!\n");
          return 1;
       }
    but if I try to use install_keyboard() or anything else, the compiler tells me that it can't find what I want it to.

    Here's my compilation line :
    Code:
    gcc -g -O3 -Wall -Wextra `pkg-config --cflags --libs allegro-5.0 allegro_monolith-5.0` -std=c11
    The monolith one was tacked on because I thought it might matter but it doesn't. How do I get this code to work because this is driving me nuts.

  2. #2
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    You need to provide more info.

    Specifically: "the compiler tells me that it can't find what I want it to"... and will have produced a lovely error that tells us exactly what it was after and where it looked.
    - Also, we need to know that you're including the right headers in your code. Seeing the relevant bits of your code might help there too.
    - Does pacman install allegro development headers as well as the library? I can't tell without having it installed but on most distros they are two separate packages (one that lets you USE Allegro in pre-compiled programs, one that lets you MAKE Allegro programs from source).
    - What's your include path generated from pkg-config? What's in that folder? Are the includes you need in there? If not, what does a search for those include files produce (i.e. are they somewhere else)?

    All pretty standard questions to ask yourself, really.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Fair enough, here's my source code :
    Code:
    #include <stdio.h>
    #include <allegro5/allegro.h>
    
    
    int main(void) {
    
    
       ALLEGRO_DISPLAY *display = NULL;
    
    
       if (!al_init()) {
    
    
          fprintf(stderr, "failed to initialize allegro!\n");
          return 1;
       }
    
    
       install_keyboard();
    
    
       return 0;
    }
    And I get the following errors,

    main.c.text+0x1b): undefined reference to `al_install_system'
    main.c.text+0x51): undefined reference to `install_keyboard'

    And here's everything Arch Linux installed (taken from https://www.archlinux.org/packages/c...86_64/allegro/),

    Package Contents

    • usr/
    • usr/include/
    • usr/include/allegro5/
    • usr/include/allegro5/alcompat.h
    • usr/include/allegro5/alinline.h
    • usr/include/allegro5/allegro.h
    • usr/include/allegro5/allegro5.h
    • usr/include/allegro5/allegro_acodec.h
    • usr/include/allegro5/allegro_audio.h
    • usr/include/allegro5/allegro_color.h
    • usr/include/allegro5/allegro_direct3d.h
    • usr/include/allegro5/allegro_font.h
    • usr/include/allegro5/allegro_image.h
    • usr/include/allegro5/allegro_memfile.h
    • usr/include/allegro5/allegro_native_dialog.h
    • usr/include/allegro5/allegro_opengl.h
    • usr/include/allegro5/allegro_physfs.h
    • usr/include/allegro5/allegro_primitives.h
    • usr/include/allegro5/allegro_ttf.h
    • usr/include/allegro5/altime.h
    • usr/include/allegro5/base.h
    • usr/include/allegro5/bitmap.h
    • usr/include/allegro5/bitmap_draw.h
    • usr/include/allegro5/bitmap_io.h
    • usr/include/allegro5/bitmap_lock.h
    • usr/include/allegro5/blender.h
    • usr/include/allegro5/color.h
    • usr/include/allegro5/config.h
    • usr/include/allegro5/debug.h
    • usr/include/allegro5/display.h
    • usr/include/allegro5/drawing.h
    • usr/include/allegro5/error.h
    • usr/include/allegro5/events.h
    • usr/include/allegro5/file.h
    • usr/include/allegro5/fixed.h
    • usr/include/allegro5/fmaths.h
    • usr/include/allegro5/fshook.h
    • usr/include/allegro5/fullscreen_mode.h
    • usr/include/allegro5/inline/
    • usr/include/allegro5/inline/fmaths.inl
    • usr/include/allegro5/internal/
    • usr/include/allegro5/internal/alconfig.h
    • usr/include/allegro5/joystick.h
    • usr/include/allegro5/keyboard.h
    • usr/include/allegro5/keycodes.h
    • usr/include/allegro5/memory.h
    • usr/include/allegro5/monitor.h
    • usr/include/allegro5/mouse.h
    • usr/include/allegro5/mouse_cursor.h
    • usr/include/allegro5/opengl/
    • usr/include/allegro5/opengl/GLext/
    • usr/include/allegro5/opengl/GLext/gl_ext_alias.h
    • usr/include/allegro5/opengl/GLext/gl_ext_api.h
    • usr/include/allegro5/opengl/GLext/gl_ext_defs.h
    • usr/include/allegro5/opengl/GLext/gl_ext_list.h
    • usr/include/allegro5/opengl/GLext/glx_ext_alias.h
    • usr/include/allegro5/opengl/GLext/glx_ext_api.h
    • usr/include/allegro5/opengl/GLext/glx_ext_defs.h
    • usr/include/allegro5/opengl/GLext/glx_ext_list.h
    • usr/include/allegro5/opengl/GLext/wgl_ext_alias.h
    • usr/include/allegro5/opengl/GLext/wgl_ext_api.h
    • usr/include/allegro5/opengl/GLext/wgl_ext_defs.h
    • usr/include/allegro5/opengl/GLext/wgl_ext_list.h
    • usr/include/allegro5/opengl/gl_ext.h
    • usr/include/allegro5/path.h
    • usr/include/allegro5/platform/
    • usr/include/allegro5/platform/albcc32.h
    • usr/include/allegro5/platform/aliphone.h
    • usr/include/allegro5/platform/aliphonecfg.h
    • usr/include/allegro5/platform/almngw32.h
    • usr/include/allegro5/platform/almsvc.h
    • usr/include/allegro5/platform/alosx.h
    • usr/include/allegro5/platform/alosxcfg.h
    • usr/include/allegro5/platform/alplatf.h
    • usr/include/allegro5/platform/alucfg.h
    • usr/include/allegro5/platform/alunix.h
    • usr/include/allegro5/platform/alwatcom.h
    • usr/include/allegro5/platform/alwin.h
    • usr/include/allegro5/platform/astdbool.h
    • usr/include/allegro5/platform/astdint.h
    • usr/include/allegro5/system.h
    • usr/include/allegro5/threads.h
    • usr/include/allegro5/timer.h
    • usr/include/allegro5/tls.h
    • usr/include/allegro5/transformations.h
    • usr/include/allegro5/utf8.h
    • usr/lib/
    • usr/lib/liballegro.so
    • usr/lib/liballegro.so.5.0
    • usr/lib/liballegro.so.5.0.10
    • usr/lib/liballegro_acodec.so
    • usr/lib/liballegro_acodec.so.5.0
    • usr/lib/liballegro_acodec.so.5.0.10
    • usr/lib/liballegro_audio.so
    • usr/lib/liballegro_audio.so.5.0
    • usr/lib/liballegro_audio.so.5.0.10
    • usr/lib/liballegro_color.so
    • usr/lib/liballegro_color.so.5.0
    • usr/lib/liballegro_color.so.5.0.10
    • usr/lib/liballegro_dialog.so
    • usr/lib/liballegro_dialog.so.5.0
    • usr/lib/liballegro_dialog.so.5.0.10
    • usr/lib/liballegro_font.so
    • usr/lib/liballegro_font.so.5.0
    • usr/lib/liballegro_font.so.5.0.10
    • usr/lib/liballegro_image.so
    • usr/lib/liballegro_image.so.5.0
    • usr/lib/liballegro_image.so.5.0.10
    • usr/lib/liballegro_main.so
    • usr/lib/liballegro_main.so.5.0
    • usr/lib/liballegro_main.so.5.0.10
    • usr/lib/liballegro_memfile.so
    • usr/lib/liballegro_memfile.so.5.0
    • usr/lib/liballegro_memfile.so.5.0.10
    • usr/lib/liballegro_physfs.so
    • usr/lib/liballegro_physfs.so.5.0
    • usr/lib/liballegro_physfs.so.5.0.10
    • usr/lib/liballegro_primitives.so
    • usr/lib/liballegro_primitives.so.5.0
    • usr/lib/liballegro_primitives.so.5.0.10
    • usr/lib/liballegro_ttf.so
    • usr/lib/liballegro_ttf.so.5.0
    • usr/lib/liballegro_ttf.so.5.0.10
    • usr/lib/pkgconfig/
    • usr/lib/pkgconfig/allegro-5.0.pc
    • usr/lib/pkgconfig/allegro-5.pc
    • usr/lib/pkgconfig/allegro_acodec-5.0.pc
    • usr/lib/pkgconfig/allegro_acodec-5.pc
    • usr/lib/pkgconfig/allegro_audio-5.0.pc
    • usr/lib/pkgconfig/allegro_audio-5.pc
    • usr/lib/pkgconfig/allegro_color-5.0.pc
    • usr/lib/pkgconfig/allegro_color-5.pc
    • usr/lib/pkgconfig/allegro_dialog-5.0.pc
    • usr/lib/pkgconfig/allegro_dialog-5.pc
    • usr/lib/pkgconfig/allegro_font-5.0.pc
    • usr/lib/pkgconfig/allegro_font-5.pc
    • usr/lib/pkgconfig/allegro_image-5.0.pc
    • usr/lib/pkgconfig/allegro_image-5.pc
    • usr/lib/pkgconfig/allegro_main-5.0.pc
    • usr/lib/pkgconfig/allegro_main-5.pc
    • usr/lib/pkgconfig/allegro_memfile-5.0.pc
    • usr/lib/pkgconfig/allegro_memfile-5.pc
    • usr/lib/pkgconfig/allegro_physfs-5.0.pc
    • usr/lib/pkgconfig/allegro_physfs-5.pc
    • usr/lib/pkgconfig/allegro_primitives-5.0.pc
    • usr/lib/pkgconfig/allegro_primitives-5.pc
    • usr/lib/pkgconfig/allegro_ttf-5.0.pc
    • usr/lib/pkgconfig/allegro_ttf-5.pc
    • usr/share/
    • usr/share/licenses/
    • usr/share/licenses/allegro/
    • usr/share/licenses/allegro/LICENSE






  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Oh wow, I'm a moron. Turns out, the name of function was changed from the stupid tutorial I was using and it's really,
    Code:
    al_install_keyboard();
    Oh wow, I feel special now T_T

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Okay, so now I have a better understanding of how to use such complex libraries and while it may be kewl in theory, it's very lame in practice. I found this example code online but I can't get it to work (from cppgameprogramming.com &bull; View topic - hello world allegro 5)

    main.c :
    Code:
    #include <allegro5/allegro5.h>
    //#include <allegro5/allegro_image.h>
    //#include <allegro5/allegro_primitives.h>
    //#include <allegro5/allegro_color.h>
    #include <allegro5/allegro_font.h>
    #include <allegro5/allegro_ttf.h>
    //#include <allegro5/allegro_audio.h>
    //#include <allegro5/allegro_acodec.h>
    //#include <allegro5/allegro_memfile.h>
    //#include <allegro5/allegro_physfs.h>
    //#include <allegro5/allegro_native_dialog.h>
    
    
    #include <cstdio>
    
    
    
    
    void init(ALLEGRO_EVENT_QUEUE* &e_queue, int w, int h, int full=0, int opengl=1)
    {
       if(full) al_set_new_display_flags(ALLEGRO_FULLSCREEN);
       if(opengl) al_set_new_display_flags(ALLEGRO_OPENGL);
    
    
       ALLEGRO_DISPLAY* display = al_create_display(w,h); //it doesn't need to be global because you can always access it by al_get_current_display();
       if(!display) printf("ERROR INITIALIZING THE DISPLAY AT %i %i!",w,h);
    
    
       e_queue = al_create_event_queue();
       if(!e_queue) printf("ERROR CREATING EVENT QUEUE!");
    
    
       al_register_event_source(e_queue, al_get_display_event_source(display));
       //al_register_event_source(e_queue, al_get_mouse_event_source());
       al_register_event_source(e_queue, al_get_keyboard_event_source());
       //al_register_event_source(e_queue, al_get_joystick_event_sourc());
    }
    
    
    int install_allegro()
    {
       if(!al_init())
       {
          printf("ERROR INITIALIZING ALLEGRO!");
          return 0;
       }
       if(!al_install_keyboard())
       {
          printf("ERROR INITIALIZING KEYBOARD!");
          return 0;
       }
    
    
       /*if(!al_install_mouse())
       {
          printf("ERROR INITIALIZING MOUSE!");
          return 0;
       }
       if(!al_install_joystick())
       {
           printf("ERROR INITIALIZING JOYSTICK!");
           return 0;
       }
       */
       /*
       if(!al_init_image_addon())
       {
          printf("ERROR INITIALIZING IMAGE ENGINE!");
          return 0;
       }
       if(!al_init_primitives_addon())
       {
          printf("ERROR INITIALIZING PRIMITIVES ADDON!");
       }
       */
       al_init_font_addon();
    
    
       if(!al_init_ttf_addon())
       {
          printf("ERROR INITIALIZING FONT ENGINE!\n");
          return 0;
       }
       /*
       if(!al_init_audio_addon())
       {
           printf("ERROR INITIALIZING AUDIO ADDON!");
           return 0;
       }
       if(!al_init_acodec_addon())
       {
           printf("ERROR INITIALIZING AUDIO CODECS!");
           return 0;
       }*/
       //al_set_physfs_file_interface();
       return 1;
    }
    
    
    int main()
    {
        ALLEGRO_EVENT_QUEUE* event_queue = NULL;
        if(!install_allegro()) return 1;
        init(event_queue,800,600);
        ALLEGRO_FONT* font_times = al_load_font("times.ttf",20,0);
        if(font_times==NULL)
        {
            printf("ERROR LOADING FONT!\n");
            return 1;
        }
    
    
        al_clear_to_color(al_map_rgb(0,0,0));
        al_draw_text(font_times,al_map_rgb(255,255,0),400,300,ALLEGRO_ALIGN_CENTRE,"Hello World");
        al_flip_display();
    
    
        ALLEGRO_EVENT ev;
        bool quit = false;
        while(!quit)
        {
            al_wait_for_event(event_queue,&ev);
            if(ev.type==ALLEGRO_EVENT_KEY_DOWN)
            {
                if(ev.keyboard.keycode==ALLEGRO_KEY_ESCAPE) quit = true;
            }
        }
    
    
        al_destroy_display(al_get_current_display());
       al_destroy_event_queue(event_queue);
        return 0;
    }
    Makefile :
    Code:
    MKFILE    = Makefile
    
    
    GCC       = g++ -g -O3 -Wall -Wextra `pkg-config --cflags --libs allegro-5.0 allegro_font-5.0 allegro_ttf-5.0 allegro_font-5 allegro_ttf-5` -std=c++11
    
    
    CSOURCE   = main.cpp
    CHEADER   = 
    OBJECTS   = ${CSOURCE:.cpp=.o}
    EXECBIN   = blasteroids
    
    
    all : ${EXECBIN}
    
    
    ${EXECBIN} : ${OBJECTS}
    	${GCC} -o $@ ${OBJECTS}
    
    
     
    %.o : %.cpp
    
    
    	${GCC} -c $<
    
    
    
    
    clean :
    	- rm ${OBJECTS} ${EXECBIN}
    
    
    
    
    again :
    	${MAKE} clean all
    Basically, I keep getting the "ERROR LOADING FONT!" message even though everything is now compiling and initializing. Anything I should be checking for specifically???

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by MutantJohn View Post
    Oh wow, I'm a moron. Turns out, the name of function was changed from the stupid tutorial I was using and it's really,
    Code:
    al_install_keyboard();
    Oh wow, I feel special now T_T
    this is one reason why I generally don't care for the C language. you can implicitly declare a function, simply by calling it.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Lol nevermind, SDL is so much easier to use and was ironically enough, already installed on my system.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-08-2012, 10:23 PM
  2. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  3. Crossplatform Sound Library -- other than SDL and Allegro
    By frenchfry164 in forum Game Programming
    Replies: 4
    Last Post: 10-14-2003, 04:27 PM
  4. GDI woes
    By cppdude in forum Windows Programming
    Replies: 4
    Last Post: 03-17-2002, 10:48 PM
  5. allegro graphics library for linux
    By oldcoyote in forum Linux Programming
    Replies: 3
    Last Post: 10-03-2001, 10:24 AM