I recently compiled Allegro-5.0 from source (following the instructions from the wiki). I didn’t get any errors during the process, so I assume it went well. However, I am getting linker errors with even the most minimal test programs:
//test.cpp
#include <allegro5/allegro.h>
int main()
{
al_init();
return 0;
}
I am compiling with
g++ `pkg-config --libs allegro-5.0` test.cpp -o test
But I always get
/tmp/ccVmmERa.o: In function `main':
test.cpp:(.text+0xf): undefined reference to `al_install_system'
collect2: error: ld returned 1 exit status
(pkg-config returns -L/usr/local/lib -lallegro, there doesn’t seem to be anything wrong with that)
Also, I can compile the examples with the the given makefile just fine, so there doesn’t seem to be anything wrong with the library. I would just try to do the same thing the makefile does to make it work, but I don’t understand it at all (I can barely write my own simple ones).
Oh, and I’m using Ubuntu 11.10 and gcc 4.7, though I don’t think that has anything to do with it.
So – why does this happen, and how can I fix it?
Put the libs last on the command line:
When linking, the order of the files and libraries matter.