Allegro
Return to Installing the Allegro LibraryCompiling from Command Line on Linux
On a Linux-based OS, a compiler can be started from the console (i.e. from the terminal). The compiler for the C++ language is usually named g++
(sometimes gcc
). To compile a program that has all the source code contained in a main.cpp
file, this command can be used:
g++ main.cpp –o prog.exec
That will produce an executable file named prog.exec
that can be run by the command:
./prog.exec
To compile a program consisting of main.cpp
and MyLibrary.cpp
files, use the command:
g++ main.cpp MyLibrary.cpp –o prog.exec
There is no need to specify the names of the header files, as they will be included from the given source code files as necessary.
To compile a program that uses Allegro library, use the command:*
g++ main.cpp `allegro-config --libs` –o prog.exec
The command:
echo `allegro-config --libs`
will print out the name of the Allegro library, after the –l option
. The library is likely to be named alleg, thus: –lalleg
. On a Linux-based OS, library file names have the prefix lib
and the extension .so
, so the actual filename is liballeg.so
. The path to the library file should be printed out after the –L
option.
(*) On some Linux distributions, you might need to use the command:
g++ `allegro-config --cflags` main.cpp `allegro-config --libs` –o prog.exec