- Online Community Forums » Installation, Setup & Configuration » Compiling from the command line with gcc

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Compiling from the command line with gcc
Member #15,884
February 2015

What library should I pass as argument to gcc in addition to -lallegro in order to compile code in which appears a call to al_show_native_message_box?

Thanks :)

Edgar Reynaldo
Major Reynaldo
May 2007

You should have a lib file with the name dialog in it. Link to that one by using -lNAME where NAME is allegro_dialog.dll or something similar and the entire filename is liballegro_dialog.dll.a, or also libNAME.a. Or else link to the monolith. What distribution of allegro are you using? Or did you compile from source? The names vary slightly.

Member #15,884
February 2015

I am on Ubuntu and I compiled from source, downloading the source through git. I typed gcc test.c -o test -lallegro -lallegro_dialog and it worked. Thanks! :)

At page 1 of allegro-5.0.10-manual.pdf, there is a list of the addons:

  • allegro_main

  • allegro_image

  • allegro_primitives

  • allegro_color

  • allegro_font

  • allegro_ttf

  • allegro_audio

  • allegro_acodec

  • allegro_memfile

  • allegro_physfs

  • allegro_native_dialog

Why can all those libraries be linked in gcc by passing their name prefixed with -l, except for the last one?

For example the arguments -lallegro_image, -lallegro_primitives, -lallegro_memfile work, but the argument -lallegro_native_dialog doesn't and should be replaced by -lallegro_dialog.

Member #7,536
July 2006

It is probably due to a naming convention confusion that occurred when they first added that addon and maybe nobody has bothered to fix it... I'm not sure. :-/ In general, there's no magic here. You can locate the Allegro libraries (shared objects) in your file system, named exactly as they are on your command line, except for having a lib prefix and so suffix per standard, as well as various symlinks with various degrees of version number (usually).

sudo updatedb
locate liballegro | grep /lib

Rather than manually specifying linker flags, you should probably be using pkg-config to manage your linker flags for you.

gcc -o test -Wall $(pkg-config --cflags allegro_5 allegro-dialog_5) \
        test.c $(pkg-config --libs allegro_5 allegro-dialog_5)

It's kind of surprising that you managed to compile and link without specifying custom header and library directories. Either you modified the install prefix or maybe Ubuntu includes /usr/local by default to make things easier (and potentially less secure)...

Go to: