Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » compiling on ubuntu

This thread is locked; no one can reply to it. rss feed Print
compiling on ubuntu
William Labbett
Member #4,486
March 2004
avatar

Hi,

I've written a program in order to get back into the swing of things.

I'm using ubuntu and haven't got a clue what I need to type into the command line
in order to compile the program.

I've got something like this in mind

gcc -c hello_world.c -o hello_world.o

but I'd like to know if this is correct apart from linker options being missing and by the way, what do I need to put as linker options on ubuntu??

#SelectExpand
1 2#include<allegro5/allegro.h> 3#include <stdio.h> 4 5 6 7 8int wait_for_key_down(void); 9 10 11int main() 12{ 13 al_init(); 14 15 al_install_keyboard(); 16 17 18 printf("Hello World!"); 19 20 21 22 23 return 0; 24} 25 26 27int wait_for_key_down(void) 28{ 29 30 ALLEGRO_EVENT_QUEUE *q = al_create_event_queue(); 31 ALLEGRO_EVENT ev; 32 33 al_register_event_source(q, al_get_keyboard_event_source()); 34 35 36 do 37 { 38 al_wait_for_event(q, &ev); 39 40 } while( ev.type != ALLEGRO_EVENT_KEY_DOWN ); 41 42 al_destroy_event_queue(q); 43 44 return 0; 45}

I'm trying to get back into programming. I want to learn about using allegro on ubuntu so I can continue programming a game I was making before juggling that and my math studies got too much and math took over.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

William! Hello and welcome back again. You've been There and Back Again so it seems. ;)

Compiling for ubuntu is pretty easy. I assume you've installed allegro 5? If not, it's really as simple as this :

sudo apt-get install liballegro5-dev

Once that's done, you can compile right away. You need to use pkg-config, or at least understand what it is doing.

g++ -Wall -g -c `pkg-config --cflags allegro-5` *.cpp

g++ -Wall -o main *.o `pkg-config --libs allegro-5`

And if you need to check which pkg config files are installed, here's a neat trick :

pkg-config --list-all | grep allegro

Those are the packages you specify when linking to allegro.

And that should be all you need!

Go to: