Running Allegro C++ code in Geany
I am very new to Allegro5. I want to run a test C++/Allegro program from inside of the Geany texteditor. When i hit the compile/build button (F9) i get errors that complain about a bunch of undefined references to some functions like: al_install_system, al_create_display etc.
Has anyone experience about using allegro in geany? Can anyone help?
If Geany supports your compiler, pass it the linker flags necessary to link the addons. Ie. if it supports MinGW (and that's what you're using) then you need to link to Allegro's library (and addons) by using -lNAME in the linker options, where the library you want to link to is named libNAME.a .
I have my altered my compile command to this:
gcc -Wall -c -lallegro "%f"
(and this is the build command: gcc -Wall -o "%e" "%f", where "%f" resolves to file)
Now when i try to build this example from the tutorial:
i still get undefined references errors. I add -lallegro also to the build command (gcc -Wall -o -lallegro "%e" "%f") and i get:
gcc -Wall -o -lallegro "tst" "tst.c"
gcc: error: tst: no such file or directory
In both cases the source code compiles fine.
What am i doing wrong?
I also tried a python example from the tutorial page: https://wiki.allegro.cc/index.php?title=Python
By running it i get ImportError:
Traceback (most recent call last):
File "tst.py", line 7, in <module>
from allegro import *
ImportError: No module named allegro
Your compiler and linker flags are wrong. -c means only output .o files. -o means set the output file to the name of the next argument.
Try compiling without your makefile for a moment until you get the command line correct.
Typically it should be something like this :
gcc -Wall -O2 -o test.o -c test.c
gcc -Wall -o test.exe test.o -lallegro_monolith
The order of the commands matters too. Files mentioned first are compiled first, and libraries are linked in the order they are encountered. (Which is why you should use -lallegro_monolith after specifying your .o files).
After the second line this appears:
/usr/bin/ld: cannot find -lallegro_monolith
collect2: error: ld returned 1 exit status
Is this something i should have installed also?
(I am on ubuntu 16.04 LTS)
Thread #616414. Printed from Allegro.cc
Don't take my command line literally. You have to replace allegro_monolith with the name of the allegro library you are using. I don't know what that is when not compiling with the monolith option, and when on Linux. Look in usr/local/lib. That's usually where it goes.
On Linux, people generally use pkg-config to link allegro. I can't help you there. You can still do it manually though.