|
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. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
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 . My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
amirteymuri
Member #16,507
August 2016
|
I have my altered my compile command to this: Now when i try to build this example from the tutorial: 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: In both cases the source code compiles fine. By running it i get ImportError: Traceback (most recent call last): |
Edgar Reynaldo
Major Reynaldo
May 2007
|
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). My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
amirteymuri
Member #16,507
August 2016
|
After the second line this appears: /usr/bin/ld: cannot find -lallegro_monolith Is this something i should have installed also? (I am on ubuntu 16.04 LTS) |
Edgar Reynaldo
Major Reynaldo
May 2007
|
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 My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|