Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Install and Set up Allegro in Linux.

This thread is locked; no one can reply to it. rss feed Print
Install and Set up Allegro in Linux.
Neil Black
Member #7,867
October 2006
avatar

Basically what the title says. I installed Ubuntu on my computer a while back, but I've just now gotten into programming. I'm compiling from the command line, which is something I've never done before (I learned something today, yay!).

So how do I get Allegro installed and set up to work from the command line. And how to I compile Allegro programs from the command line?

Thomas Fjellstrom
Member #476
June 2000
avatar

If you want to skip compiling allegro, just use apt-get or aptitude to install allegro (aptitude install liballegro-dev).

Otherwise, you get to download and extract (tar zxf allegro-4.2.2.tar.gz) allegro to some directory. After that you can follow the install directions in doc/build/linux.txt.

As for compiling from the command line:

debug:
gcc -W -Wall -ggdb3 -pipe file.c -o program `allegro-config --libs`

release:
gcc -W -Wall -s -O2 -pipe file.c -o program `allegro-config --libs`

NOTE: those (`) are backticks, not quotes.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Neil Black
Member #7,867
October 2006
avatar

Quote:

gcc -W -Wall -s -O2 -pipe file.c -o program `allegro-config --libs`

I keep getting an "unrecognised option '-02'" error.

What are all those different options for? the only one I recognise it '-o'.

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

I keep getting an "unrecognised option '-02'" error.

Its an O (the letter) not a 0 (the number) ;)

Quote:

What are all those different options for? the only one I recognise it '-o'.

-W and -Wall turn on warnings that you NEED to properly program.
-s tells gcc to strip all extraneous symbol information from the files (it cripples debugging, so don't use it on a debug build).
-O is the "optimization" flag, it accepts an integer from 0 through 9 (but only up to 3 happens to exist, and you don't want to use 3 in most cases), and the letter s to optimize for code size instead of performance.
-g tells gcc to embed lots and lots of debuging information into the code, and the generated object files and binaries, it takes a number of strings to tell it what format of debug info, I find gdb3 works the best, the most often, though stabs+ might work better for C++ (it used to, but it may not anymore, I dunno).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Milan Mimica
Member #3,877
September 2003
avatar

That's O, not 0.
There's the manual: man gcc.

Neil Black
Member #7,867
October 2006
avatar

Quote:

There's the manual: man gcc.

I typed g++ man instead of man g++ for some reason.

It's working now. I only have one more question, how do I compile multiple files?

Milan Mimica
Member #3,877
September 2003
avatar

You specify multiple files.

Evert
Member #794
November 2000
avatar

Quote:

I only have one more question, how do I compile multiple files?

By specifying more than one file on the command line.

That's not actually the proper way to do it though: the proper way is to compile each file into an object fie and then link the different object file together. That way you don't need to recompile all your source code all the time, just the source that has changed.
This is what Make can automate for you: you just have to tell it what object files to link and what source file produces what object file, and you're good.

CosmicR
Member #6,889
February 2006
avatar

I just wrote a tutorial on exactly this how to install allegro in my blog, see my sig!

Thomas Fjellstrom
Member #476
June 2000
avatar

The one file at a time command would look like so:

compile:
gcc -W -Wall -ggdb3 -c file.c

link:
gcc *.o -o program `allegro-config --libs`

Once you get into more than a few source files you may want to think about using makefiles or CMake (or scons for that matter). Makes things a lot easier.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Neil Black
Member #7,867
October 2006
avatar

Quote:

aptitude install liballegro-dev

That installs Allegro 4.2, right?

Thomas Fjellstrom
Member #476
June 2000
avatar

Yup. Least till they package 4.4 or 5+

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: