Skip navigation

White paper: Installing and Using Multiple Versions of GCC

White paper: Installing and Using Multiple Versions of GCC


Tellurian specialises in cross-platform development, and GCC makes this much easier.

These instructions show how to install multiple versions of GCC (the Gnu Compiler Collection) on the one system. They are based on Linux systems, but should be equally applicable to other flavours of Unix. Note that we only show a native installation here, not a cross-compilation. Native compilation is preferred where possible as it simplifies the development and testing process. Cross-compilation is also important, but is not discussed here.

There are various options and different ways of doing things which are possible which are not discussed here. Neither are the automated test steps. This article is intended only as a simple introduction. As with just about anything on Unix, there is always more than one way to do something.

We aim to install the different versions of gcc into /usr/local/gcc/<version>/ where <version> is for example 3.4.0. These multiple versions will happily function alongside a "default" installation, which is usually in /usr/bin/gcc. We also show how to easily switch between these versions when building your software.


You will need a version of GCC already installed. The build process will use quite a bit of space, as much as 700 MB, which can be deleted once the installation is complete. The target installation will typically need about 250 MB. The build process will take a long time, possibly an hour or two depending on the speed of your system.


The page of mirrors lists FTP sites which have various versions of GCC for download. Choose a mirror site closest to you, and then download the desired release of GCC from there.

For example, at the time of writing GCC 3.4.0 is the current release, so download gcc-3.4.0.tar.bz2 from /gcc/releases from a local mirror. This file is roughly 27 MB, and contains all components of GCC, including the different compilers and test tools.


For this article, we assume that we build GCC within your home directory tree.

From your home directory, expand the archive, eg:


			tar -xjf


This creates directory ~/gcc-3.4.0/. We need to also create a directory for building, and go to it, eg:

			mkdir gobj

			cd gobj



We run the configure script with the options we need. For this example, we default just about everything except the destination directory tree. We install our target under /usr/local/gcc/, using the version number as part of the path so that we can then select different compilers easily.

			~/gcc-3.4.0/configure --prefix=/usr/local/gcc/3.4.0



To compile the system, enter the following:

			make bootstrap


Go and have a coffee. Don't rush back. As a guide, this takes roughly an hour on a 1300 MHz Celeron when building GCC 3.4.0.


This step is optional. If you want to build the Ada compiler component of GCC, you'll need to already have Gnat installed. To build the Ada compiler, use these (optional) steps:

			cd gcc

			make gnatlib_and_tools

			cd ..



This step is optional. If you like, you can run a large set of automated tests against your new compiler before you install it. This will take a long time, and produce a set of pass/fail results. Most likely some steps will fail, refer to the GCC Test page for more information. You will need to have DejaGnu installed to perform these tests.

			make -k check


Ignore warnings about configuration files which couldn't be found. This process takes a long time, and then produces a set of log files which can be compared with those at Gnu's site.


To install the software you need to become root as per the following steps:

			su -l

			cd ~yourusername/gobj

			make install




Enter the following command as a very rudimentary test:

			/usr/local/gcc/3.4.0/bin/g++ -v


This should report the version number of the compiler installed.

Cleaning Up

You can now remove files which are no longer needed. eg:


			rm -rf gobj/

			rm -rf gcc-3.4.0/



To switch between different versions of GCC, put the following fragment near the top of your Makefile:

			# Choose the version of GCC that we want to use

			GCC_VERSION = 3.4.0

			PREFIX = /usr/local/gcc/${GCC_VERSION}/bin/

			CC = ${PREFIX}gcc

			CPP = ${PREFIX}g++


Changing the value of the GCC_VERSION symbol will then let you compile using different installed versions of GCC. There are other ways of switching between compiler versions, but this is a simple easy-understandable method. If you want to compile against your default installed compiler (eg on Redhat, in /usr/bin/g++), instead use the following fragment:

			CC = gcc

			CPP = g++


You could then repeat this process for other versions of GCC, so that you could for example have one of each the 3.1, 3.2, 3.3, and 3.4 series compilers for testing. As the C++ ABI has changed from 3.1 to 3.2, and again slightly from 3.3 to 3.4, this can be handy for code migration as well.

Any questions, feel free to email us at