4

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

  • 1
    Please at least summarize the error in your question - don't expect us to read a whole 1200+ line log file – steeldriver Jun 8 '17 at 11:52
  • @user7706975 : Did the answer work ? – ankit7540 Jun 10 '17 at 9:26
  • Yes, it did.. Thank you @ankit7540 and apologies for late reply. – user7706975 Jun 16 '17 at 10:46
  • @user7706975 : In order to close this question, you should accept an answer. – ankit7540 Jun 17 '17 at 1:38
8

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.
  • * sudo update-alternatives code is updated in the post. – ankit7540 Jun 8 '17 at 11:01
  • Hi @ankit7540, thanks for your detailed answer. But, what do you think about Oriol 's comment? I just want to make sure before things get messed up. – user7706975 Jun 8 '17 at 11:02
  • * Above solution checked on 14.04. Found to be working. – ankit7540 Jun 8 '17 at 11:02
  • I have been using this method to compile several applications which have different requirements. About Oriol's comment, it is focused on the downgrading a package to older version and keep it intact, that is, not update it in future. – ankit7540 Jun 8 '17 at 11:05
  • 1
    If you want to use a C/C++ compiler temporarily for one build, an alternative is to use environment variables. CC=/path/to/other/gcc-1.2 or CXX=/path/to/other/g++-1.2, either set more permanently (export) or for a particular call: CC=/path/to/other/gcc-1.2 ./configure --with-everything && make. You might also use checkinstall or pogo instead of make install in order to make the uninstallation afterwards easier. – Oleg Lobachev Oct 10 '17 at 18:17
0

It's not possible to have to versions of the same package, as they would be conflicting files,for example: you'd have trouble while trying to update one of the packages as they would be placed in the same location.

Having said that you have the option to downgrade the version of the program to an older one, here comes the how to:

  1. open a terminal emulator and type apt-cache showpkg <package-name> a list of the available versions will be printed
  2. Then type sudo apt-get install <package-name>=<package-version-number> to install the version you prefer
  3. type apt-mark hold <package-name> this will prevent the package from being updated
  4. if you have any trouble type man apt to open the command's manual

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.