Setting Up Allegro on Linux

Peter Hull
[email protected]
5th October 2001

This file is a brief guide on how to get Allegro up and running on your Linux system. I can only describe my experience; if you encounter differences on your system, please let me know. For reference, I am setting up Allegro WIP 3.9.38 on an Intel system running Mandrake Linux 7.2. This isn't a substitute for reading the files that come with Allegro; readme.txt, readme.uni, readme.lnx and faq.txt. If you have problems, go there first, and if that fails to help, try the Forums on Allegro.cc. Here, I also cover the bits before and after compiling Allegro itself. I am assuming that you can use the Linux command prompt, sh, and that you can program in C or C++. I am fairly new to Unix myself, so I'd appreciate comments or suggestions on this, at the address above.

Prerequisites

To get started, you'll need a working Linux development environment. Virtually all Linux distributions will have GCC, the GNU compiler collection. This allows you to create programs in C and C++. Start up a terminal window and type
gcc -v
You should get something like
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)

If GCC is not installed (I'd be surprised if it wasn't), you'll need to run your package manager, and install the packages. See the appendix.

Being root

At some stage, you will need root access if you want to make Allegro available to all users. You could just install it in your home directory, but this requires a little more setting up. Can I just say here, do not log on as root. Unix puts obstacles in your way to prevent you from doing anything silly, but once you go beyond that, you are on your own. It's very easy for root to make the whole system unusable, and there's rarely anything like 'undo' to help you out. I speak from bitter experience! If you need root access, do a su -c "command" and type your password. This makes you root for the duration of that command only. You'll see when you need it as you'll get errors like "permission denied."

Compiling Allegro

The next stage is to get a copy of Allegro itself. Try  SourceForge , the current home page for Allegro, and get the latest .rpm version. If you have Debian Linux, I think you'll need to get the .tar.gz version as Debian doesn't use .rpm files. Then, just use your package manager to install it. If you're using K, it's called kpackage, and if you're using gnome, it's gnorpm. Just see the documentation for those programs. Installing the package should also begin the compilation process automatically.  Type
allegro-config --version
and you should see something like
3.9.38
If you don't you may need to compile Allegro manually. This also applies if you downloaded Allegro as a .tar.gz or even a DOS/Windows .zip. If you have one of these types of archives, unpack it in a new directory. See the man pages for tar or unzip to find how to do this.
Go to the directory where you unpacked Allegro. Type
sh fix.sh unix
./configure
make
The first command is needed if you want to convert a DOS or Windows version to Unix; it doesn't do any harm to run it anyway. The second sets up the makefile, and the third actually compiles the library.
You may want to explore some of the build options. Type ./configure --help to see them. These allow you to specify many options, such Pentium optimizations, and also to make the debug or profiling libraries. For example, ./configure --enable-dbglib=yes
make
If there's no configure file at all, type autoconf to generate it from the configure.in file.
Finally, install it, using make install. Here's where you will probably need su -c "make install".Test the installation with allegro-config --version.

Creating Allegro programs

I always use a makefile to automate compilation. See the man pages for make, for more information. A simple makefile might be

CFLAGS=-O `allegro-config --cflags`
LDLIBS=`allegro-config --shared`
LDFLAGS=-s

myprog: myprog.o




Which will automatically run
cc -c -O -I/usr/local/include myprog.c -o myprog.o
cc -s myprog.o -o myprog -L/usr/local/lib -lalleg-3.9.38 -lalleg_unsharable

The allegro-config is a bit of magic that selects the right include files and libraries for your program to use. Try typing one of those allegro-config commands in; that's what it expands to in the compiler line.

Linux for DOS/Windows folks

There are a few differences that can confuse people accustomed to DOS or Windows.

Executable files

These don't have an .exe suffix, so the example above is called myprog, not myprog.exe. Second, the shell does not look in the current directory for programs, so if you type myprog, you'll get
bash: myprog: command not found
Type ./myprog instead. If you still get errors, like
bash: ./myprog: Permission denied
it probably means the program is not readable or not executable by you. Use chmod to change it, for example chmod u+x myprog.

Screen modes

Allegro on Linux seems a little bit less flexible in what screen modes it provides. Be sure to check set_gfx_mode for errors. Also, running a program fullscreen means either using fullscreen X (slow) or DGA, SVGAlib or FBcon, which require root privileges to run. See the file readme.lnx in the Allegro directory.

Filenames

Remember that Unix file names are case-sensitive, so if you #include <Allegro.h> it will work in DOS but not on Unix. Use #include <allegro.h>.
There are some differences in file endings compared to Visual C++ and Borland C++.
Visual C++GCC
Object files.obj.o
C++ files.cpp.cc or .cpp
Library files.lib.a

The main function

Don't forget to use END_OF_MAIN(); at the end of your main(). Also, if your program takes command line arguments, be aware that the shell will expand any wildcards before the program gets them. This is also true for DJGPP and MinGW, but I don't know about Visual C++. This is a Unix thing rather than Allegro specific. It means that if your directory contains files b1.bmp, b2.bmp and b3.bmp, typing
prog *.bmp
is the same as typing
prog b1.bmp b2.bmp b3.bmp
If you want the program to get the wildcard, type prog "*.bmp"

Otherwise, I think you'll be surprised at how little you need to do to get a well-written DOS program to run on Linux. Congratulations to the Allegro creators!

Conclusions

Once you've got a Linux set-up, it really is straightforward to get Allegro ready, because you'll already have all the programming tools available. You won't have to go searching (or paying) for a good compiler.
Once you get Allegro compiled and installed, search out some of the many tutorials on the web. The rest should be applicable to any of the platforms that Allegro runs on.
Good luck, and don't forget to let me know how you get on.

Pete

Appendix - programming environment

If you don't have GCC installed, look for packages on your Linux distribution CD. The ones to go for are and if you want C++ On Mandrake, you can also select "Development PC" from the install options, which grabs all these and more.