Undefined symbols when compiling Allegro code

  allegro5, c++, macos

I am trying to get started with the Allegro game development library for C++ on Mac OS Catalina 10.15.4, but I am having some issues with compilation and linking. The following code compiles:

#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_font.h>
#include <iostream>

#define ScreenWidth 375
#define ScreenHeight 667

int main(int argc, char *argv[]){
  
  al_init();
  /*
  al_init_font_addon();
  al_init_ttf_addon();
  */
  ALLEGRO_DISPLAY* display;
  //ALLEGRO_FONT* font = al_load_ttf_font("aArang.ttf",64,0);
  display= al_create_display(ScreenWidth,ScreenHeight);
  al_set_window_position(display,200,100);
  al_set_window_title(display, "Grapevine Groove");
  while(true){
    al_clear_to_color(al_map_rgb(255,255,255));
    //al_draw_text(font,al_map_rgb(0,0,0),0,0,0,"Hello World!");
    al_flip_display();
  }
  al_rest(1.0);
  return 0;
}

However, as you can see, lines which reference certain packages from within Allegro are commented out. When those lines are un-commented and compiled, they don’t link to the correct packages. I have searched different forums and tried editing my makefile in various ways to no avail. I saw that Allegro can be compiled with a monolith setting to link all of its packages, but I’m not sure if/how to do this with my Allegro version (I think I have 5.2.6). The linking error is below:

Undefined symbols for architecture x86_64:
  "_al_draw_text", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
  "_al_init_font_addon", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
  "_al_init_ttf_addon", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
  "_al_load_ttf_font", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [clean] Error 1

I read that the add ons have to be separately installed on Windows and Linux from the main Allegro lib, but I installed Allegro through Homebrew and am not sure how that would work.

Source: Windows Questions C++

LEAVE A COMMENT