Wednesday, December 24, 2008

Installing GCC on Eee PC: A Walkthrough

This is a step-by-step walkthrough of how to build and install latest GCC (4.3.2 at the time of writing) from source on Eee PC 900 model with pre-installed Linux. The steps for other models may be similar but there's no way I can test it now.

0. Why do I need a GCC?

Well, why not? I cannot bear the fact that Eee PC does not come with a pre-installed gcc, since this basically says, hey, we don't want you to build your own stuff on it. What a thing to do, considering that they have already provided the assembler (as), linker (ld), pre-processor (cpp), text editor (vim), GNU make, Perl, Python, and many more!

The system itself is Xandros based. No problem. But it's the stable release. Err, can't they take a little risk and provide more up-to-date software? Firefox is of version after upgrading, for example, and "Check for Update" is disabled within firefox.

I may be able to use it to check email for now, but I felt the urge to take control. So here's what I did as a first step to extend the system.

1. Preparations

1.1 Getting a shell

I am a gnome user, so the user interface looks a bit like maze to me. The first thing I tried in my local retailer was to launch a console program. It took me a good 10 minutes to find a way. Basically you could open a file manager and press Ctrl-T, which would give you a full fledged Konsole. But I later learned that there's an easier way: Just press Ctrl-Alt-T on the main desktop interface and you will get an xterm.

1.2 Preparing directory

My 900 model comes with a claimed 20G solid state disk. It was divided into two partitions, one of them 3.7G mounted as / and and the other 14.7G mounted as /home. The first partition, being used mainly by the pre-installed system, already took most of the space on it. So it's not a good idea to directly install anything there. However, installing everything to user home directory is inconvenient, since you need to modify default prefix when building, and makes installation of binary packages more difficult.

My solution is to move the entire /usr/local/ in to /home, and create a symbolic link there to refer to the one in /home. The commands to achieve this are:

sudo mv /usr/local /home
sudo ln -s /home/local /usr/

1.3 Getting a binary gcc package

The fact that Eee PC does not come with a compiler makes things a bit difficult to bootstrap. To compile GCC, you need GCC :)

The solution is, naturally, to get a minimum binary package from somewhere first. I first thought Debian packages would work, but I was wrong. Debian packages are tagged with an extra string after the normal package name and version number to identify which release it belongs to. This creates dependency problems. After some googling I found the following method to get gcc-4.1.2 from a xandros repository.

First, add the following line in /etc/apt/sources.list

deb xs2.0-xn main

Next, update the list of available packages by

sudo apt-get update
sudo apt-get install xandros-archive-keyring

The second command is just to let the system accept the public key of the xandros repository. After that, install gcc and libc6-dev as follows

sudo apt-get install gcc
sudo apt-get install libc6-dev

These may prompt you to install extra packages, such as linux-headers, but that's fine, and it won't take too much space. After this I got a working C compiler.

2. Building GCC

A detailed instruction of how to build GCC from source can be found at However, many of the steps and options are not relevant here. So I'm going to zoom in to those things that are not the default.

2.1 Download the source

Three packages will be needed. First is GCC itself, then GMP, and lastly MPFR. Links can all be found from the gcc instruction page. There are two things to note here. One is that you only need the source of all three packages. GMP and MPFR will be built together with GCC. Second, if you are not so keen to compile Ada and Fortran etc. using gcc, you can just get gcc-core and gcc-g++ packages, which will be about only half of the size of the full version.

After downloading the source packages, decompress them in the same directory. I used /home/user/sw/. Each of these packages will have their own sub directory (except for gcc-g++ and gcc-core, they will go into the same directory).

2.2 Building from source

Before you actually start to build, you need to tweak the directories a bit. Suppose you are in /home/user/sw/ (replace this by wherever you decompress the source files). Also, suppose you downloaded gcc-4.3.2, gmp-4.2.4 and mpfr-2.3.2. You can do the following.

mkdir build
cd gcc-4.3.2
ln -s ../gmp-4.2.4 gmp
ln -s ../mpfr-2.3.2 mpfr

After that you can start to configure GCC in the "build" directory as created above (building inside the source directory is not recommended as stated on the gcc webpage).

cd /home/user/sw/build

By default the installation directory prefix is /usr/local/, which can be changed by "--prefix=dir" parameter to the configure script. After that you can start to build and install it.

sudo make install

Verify that you are using the new gcc by "gcc --version". I had to exit the current xterm and launch a new one to do that because although /usr/local/bin is before everything else in $PATH, somehow when I run gcc it still runs the old version in the existing xterm window.


Anonymous said...

You say:

"First, add the following line in /etc/apt/sources.list"

but you don't say how to access "/etc/apt/sources.list". If I type that in the command module (Clt+Alt+T) it says it won't allow me access it because I don't have the permission to do so.

Note that when you open the command module, you are in /home/user. I don't know whether this might explain the problem I'm experiencing...

Anonymous said...

Hi again,

I just found elsewhere the solution to the problem I just mentioned: I had to type in the following:

sudo kwrite /etc/apt/sources.list