3

I followed to steps to build and install Allegro 5 from their wiki (found here: https://wiki.allegro.cc/index.php?title=Main_Page) and seemingly succeeded with no problems.

allegro was installed to the following (as the wiki suggests) /usr/local/include and usr/local/lib and I have confirmed allegro is there.

I then wrote the following code in vim:

#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;
}

I am new to using Unix and have only ever compiled c++ programs with g++ that were simple hello world files with no libraries needed.

Therefore after searching around on the internet I tried the following commands:

g++ hello.cpp -o hello `pkg-config --libs allegro-5`

resulting in the following:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
  implicit entry/start for main executable
  (maybe you meant: __al_mangled_main)
ld: symbols not found for architecture x86_64
clang: error: linker command failed with exit code 1

BTW, I used homebrew to install dependencies instead of macports

brew install pkg-config brew install zlib etc...

It seems like a linking problem.

What am I doing wrong?

6
  • Try using $(pkg-config --libs allegro-5) rather than `pkg-config --libs allegro-5`
    – l'L'l
    Commented Mar 4, 2015 at 6:48
  • I just tried that and it results in the same error. I think it is something to do with things not being linked properly, but I don't know how to fix it. Commented Mar 4, 2015 at 6:51
  • Are you trying to compile with static libs or dynamic? and what is the output of the command: pkg-config --libs allegro-5
    – l'L'l
    Commented Mar 4, 2015 at 6:54
  • I am using static libs (at least I think I am. see here: wiki.allegro.cc/index.php?title=Install_Allegro5_From_GIT/…) "building static allegro with make" output is: -L/usr/local/lib -lallegro Commented Mar 4, 2015 at 6:56
  • 2
    Nice, put that as an answer and accept it. :) (must have been the allegro_main-5 part that was key)?.
    – l'L'l
    Commented Mar 4, 2015 at 7:12

1 Answer 1

7

try install allegro with homebrew and use gcc -o main main.c -lallegro -lallegro_main

because the allegro_main is a compatibility library that allows the main function to work on all compilers. Required only from OS X.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.