0

I am trying to compile a simple allegro5 program on Mac OSX 10.12 but am getting an undefined symbols error. Here is the command I ran in the terminal

gcc main.c -o hello -I/usr/local/include/ -L/usr/local/lib -lallegro_main

And here is my code.

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv)
{

ALLEGRO_DISPLAY *display = NULL;

if(!al_init())
{
    fprintf(stderr, "failed to initialize allegro!\n");
    return -1;
}

display = al_create_display(640, 480);
if(!display)
{
    fprintf(stderr, "failed to create display!\n");
    return -1;
}

al_clear_to_color(al_map_rgb(0,0,0));

al_flip_display();

al_rest(10.0);

al_destroy_display(display);

return 0;
}

Here is the error I get

Undefined symbols for architecture x86_64:
  "_al_clear_to_color", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_create_display", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_destroy_display", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_flip_display", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_install_system", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_map_rgb", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_rest", referenced from:
      __al_mangled_main in main-b86b99.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is it possible that I did not install allegro correctly? I installed it using homebrew according to the allegro wiki instructions. https://wiki.allegro.cc/index.php?title=Getting_Started#Mac_OS

Guilty Spark
  • 77
  • 10

1 Answers1

0

Those are linker errors. You need to link to lallegro.

rcorre
  • 6,477
  • 3
  • 28
  • 33
  • That's what the `-lallegro_main` is for. As far as I can tell, the search path and library path are correct. – Guilty Spark Apr 20 '17 at 16:56
  • `lallegro` is not the same as `lallegro_main`. `lallegro` provides most of the core functionality, `lallegro_main` is just for the main function (and I think is just required for MacOS). Although I'm not seeing an undefined reference for `al_init`, so I might be wrong here... – rcorre Apr 20 '17 at 19:40
  • The `allegro_main` module [depends on](http://liballeg.org/a5docs/trunk/getting_started.html) the `allegro` module. So I would try adding the `-lallegro` flag to your `gcc` call in addition to `lallegro_main` – rcorre Apr 20 '17 at 19:43