Installing an older gcc version(3.4.3) on Ubuntu 14.04 (currently 4.8 installed)

I have gcc 4.8 installed but I also need to install gcc 3.4.3. I have followed these steps:

  1. Downloaded gcc 3.4.3 from gcc.parentingamerica.com/releases.
  2. Extracted the tar.
  3. ./configure
  4. make

Then it throws this error: http://paste.ubuntu.com/24807240/

Please can anyone suggest what's wrong and also how to ask gcc to use the older version once installed?

OS: Ubuntu 14.04 LTS, 64-bit


Solution 1:

Check your current version by running gcc -v.

Next, You want to install a previous version.

  1. For gcc-3.4

Since this version is available in the older releases of Ubuntu, we need to have the appropriate repositories for the version. From some search, I found them to be the following, which have to be added to the /etc/apt/sources.list

deb     http://snapshot.debian.org/archive/debian/20070730T000000Z/ lenny main
deb-src http://snapshot.debian.org/archive/debian/20070730T000000Z/ lenny main
deb     http://snapshot.debian.org/archive/debian-security/20070730T000000Z/ lenny/updates main
deb-src http://snapshot.debian.org/archive/debian-security/20070730T000000Z/ lenny/updates main

Then after doing sudo apt-get update the new repositories will be available.

Next, install the required compiler. I usually install gcc and g++ of the same version for inter-operability. For general purpose it is recommended.

Hence,

sudo apt-get install gcc-3.4 g++-3.4

2. Checking the available compilers

At this stage one will have two set of compilers (one each for g++ and gcc). These can be checked by dpkg --list | grep compiler,

dpkg --list | grep compiler

dpkg --list | grep compile
ii  g++                                                   4:4.8.2-1ubuntu6                                    amd64        GNU C++ compiler
ii  g++-3.4                                               3.4.6-5                                             amd64        The GNU C++ compiler
ii  g++-4.8                                               4.8.4-2ubuntu1~14.04.1                              amd64        GNU C++ compiler
ii  gcc                                                   4:4.8.2-1ubuntu6                                    amd64        GNU C compiler
ii  gcc-3.4                                               3.4.6-5                                             amd64        The GNU C compiler
ii  gcc-4.8                                               4.8.4-2ubuntu1~14.04.1                              amd64        GNU C compiler
ii  hardening-includes                                    2.5ubuntu2.1                                        all          Makefile for enabling compiler flags for security hardening
ii  libllvm3.6:amd64                                      1:3.6-2ubuntu1~trusty1                              amd64        Modular compiler and toolchain technologies, runtime library
ii  libxkbcommon0:amd64                                   0.4.1-0ubuntu1                                      amd64        library interface to the XKB compiler - shared library
ii  pkg-config                                            0.26-1ubuntu4                                       amd64        manage compile and link flags for libraries

You can check the installation location if you need that.

Important is the location of the two set of compilers, which can be listed by,

ls -lh /usr/bin/gcc*
lrwxrwxrwx 1 root root    7  5月 13  2016 /usr/bin/gcc -> gcc-4.8
-rwxr-xr-x 1 root root  91K  1月  4  2007 /usr/bin/gcc-3.4
-rwxr-xr-x 1 root root 758K  1月 27  2016 /usr/bin/gcc-4.8

and

    ls -lh /usr/bin/g++*
lrwxrwxrwx 1 root root    7  4月  8  2014 /usr/bin/g++ -> g++-4.8
-rwxr-xr-x 1 root root  93K  1月  4  2007 /usr/bin/g++-3.4
-rwxr-xr-x 1 root root 758K  1月 27  2016 /usr/bin/g++-4.8

  1. Selecting a compiler for current purpose (building an application)

After having required compilers installed one can simply switch among compilers. This is done by updating the list of alternative versions of an application. To do this, the update-alternative command has to be run with certain parameters.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.4 40 --slave /usr/bin/g++ g++ /usr/bin/g++-3.4
sudo update-alternatives --config gcc

This will link g++ to gcc and on changing only gcc the g++ will change automatically.

Then whenever you want to change the compiler enter this:

sudo update-alternatives --config gcc

Then, user is asked which compiler to choose.

    sudo update-alternatives --config gcc
    There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

      Selection    Path              Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/gcc-4.8   60        auto mode
      1            /usr/bin/gcc-3.4   40        manual mode
      2            /usr/bin/gcc-4.8   60        manual mode

Press enter to keep the current choice[*], or type selection number:

Here you can choose by pressing the key(0,1) and then pressing enter. The change in the current selected version can be checked by gcc -v


Removing the update-alternative

  1. If you want to keep the alternative compiler installed. Then just change to auto mode in update-alternative that is option 0.
  2. If you want to remove the alternative compiler, then remove the compiler like as sudo apt-get remove gcc-3.4 g++-3.4 then run

sudo update-alternatives --config gcc

The program update-alternatives will look for links and found them to be missing and will automatically remove the alternative, going back to the other available option.

sudo update-alternatives --config gcc
update-alternatives: warning: alternative /usr/bin/gcc-3.4 (part of link group gcc) doesn't exist; removing from list of alternatives
There is only one alternative in link group gcc (providing /usr/bin/gcc): /usr/bin/gcc-4.8
Nothing to configure.