0

External symbol reference imp_al_create_builtin_font unresolved in function main I want to make a game with Allegro library. But at the beginning, I have encountered the above error (c/c++ language).

#include <allegro5/allegro5.h>
#include  <allegro5/allegro_font.h>

int main()
{
    al_init();
    al_install_keyboard();

    ALLEGRO_TIMER* timer =      al_create_timer(1.0 / 30.0);
     ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
    ALLEGRO_DISPLAY* disp = al_create_display(320, 200);
    ALLEGRO_FONT* font = al_create_builtin_font();

     al_register_event_source(queue, al_get_keyboard_event_source());
    al_register_event_source(queue, al_get_display_event_source(disp));
    al_register_event_source(queue, al_get_timer_event_source(timer));

    bool redraw = true;
    ALLEGRO_EVENT event;

    al_start_timer(timer);
    while(1)
    {
        al_wait_for_event(queue, &event);

        if(event.type == ALLEGRO_EVENT_TIMER)
            redraw = true;
        else if((event.type ==     ALLEGRO_EVENT_KEY_DOWN) || (event.type ==     ALLEGRO_EVENT_DISPLAY_CLOSE))
             break;

        if(redraw && al_is_event_queue_empty(queue))
    {
            al_clear_to_color(al_map_rgb(0, 0, 0));
            al_draw_text(font, al_map_rgb(255, 255, 255), 0, 0, 0, "Hello world!");
            al_flip_display();

            redraw = false;
        }
    }

    al_destroy_font(font);
    al_destroy_display(disp);
    al_destroy_timer(timer);
    al_destroy_event_queue(queue);

    return 0;
}
273K
  • 29,503
  • 10
  • 41
  • 64
MH KA
  • 1
  • I also used the al_destroy_font function and other functions to finish the game, but only this function encountered the same error.Visual Studio shows the error location as o.obj – MH KA Dec 18 '22 at 03:20
  • 1
    You need to link with the library that provides the font routines, probably called something like `allegro_font`. – Retired Ninja Dec 18 '22 at 03:22
  • `imp_al_create_builtin_font` the imp_ part says you need to link to an import library for a dll. – drescherjm Dec 18 '22 at 03:23
  • [https://liballeg.org/a5docs/trunk/font.html](https://liballeg.org/a5docs/trunk/font.html) says link to `allegro_font` ***These functions are declared in the following header file. Link with allegro_font.*** – drescherjm Dec 18 '22 at 03:25
  • [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – WhozCraig Dec 18 '22 at 03:30

0 Answers0