Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Running Allegro C++ code in Geany

This thread is locked; no one can reply to it. rss feed Print
Running Allegro C++ code in Geany
amirteymuri
Member #16,507
August 2016

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?

Edgar Reynaldo
Member #8,592
May 2007
avatar

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 .

amirteymuri
Member #16,507
August 2016

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:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3 4int main(int argc, char **argv){ 5 6 ALLEGRO_DISPLAY *display = NULL; 7 8 if(!al_init()) { 9 fprintf(stderr, "failed to initialize allegro!\n"); 10 return -1; 11 } 12 13 display = al_create_display(640, 480); 14 if(!display) { 15 fprintf(stderr, "failed to create display!\n"); 16 return -1; 17 } 18 19 al_clear_to_color(al_map_rgb(0,0,0)); 20 21 al_flip_display(); 22 23 al_rest(10.0); 24 25 al_destroy_display(display); 26 27 return 0; 28}

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

Edgar Reynaldo
Member #8,592
May 2007
avatar

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).

amirteymuri
Member #16,507
August 2016

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)

Edgar Reynaldo
Member #8,592
May 2007
avatar

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.

Edit
On Linux, people generally use pkg-config to link allegro. I can't help you there. You can still do it manually though.

Go to: