Monday, December 30, 2019

Ubuntu Bionic: Downgrade from GCC 7 to 4

I wrote about installing GCC 7.x and setting the default version of GCC to 7.x on Ubuntu Bionic 18.04. What if you need to chanage the default version of GCC back to 4.x?


Install GCC Toolchain 4.8

Ubuntu Bionic's default version of GCC is 7.4.0.


hanxuel@xcdl190201 ~$ apt show gcc
Package: gcc
Version: 4:5.3.1-1ubuntu1
Priority: optional
Section: devel
Source: gcc-defaults (1.150ubuntu1)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 45.1 kB
Provides: c-compiler
Depends: cpp (>= 4:5.3.1-1ubuntu1), gcc-5 (>= 5.3.1-3~)
Recommends: libc6-dev | libc-dev
Suggests: gcc-multilib, make, manpages-dev, autoconf, automake, libtool, flex, bison, gdb, gcc-doc
Conflicts: gcc-doc (<< 1:2.95.3)
Task: ubuntu-desktop, ubuntu-usb, kubuntu-desktop, kubuntu-full, edubuntu-desktop, edubuntu-usb, xubuntu-core, xubuntu-desktop, mythbuntu-frontend, mythbuntu-desktop, mythbuntu-backend-slave, mythbuntu-backend-master, ubuntustudio-desktop-core, ubuntustudio-desktop, ubuntu-gnome-desktop, ubuntukylin-desktop
Build-Essential: yes
Supported: 5y
Download-Size: 5,244 B
APT-Manual-Installed: yes
APT-Sources: http://xcd-engyum.xilinx.com/ubuntu160405 xenial/main amd64 Packages
Description: GNU C compiler
 This is the GNU C compiler, a fairly portable optimizing compiler for C.
 .
 This is a dependency package providing the default GNU C compiler.




For GCC 4.x series, GCC 4.8.5 is available.

You will need to install the following packages:
  • gcc-4.8
  • g++-4.8
  • libgcc-4.8-dev
  • gcc-4.8-multilib
  • gcc-ar-4.8
  • gcc-nm-4.8

Basically

$ sudo apt-get install  gcc-4.8g++-4.8 libgcc-4.8-dev gcc-4.8-multilib gcc-ar-4.8 gcc-nm-4.8

Next, we will be practically undoing what we have done in the previous article. Setting the default version of GCC to 4.8

Set Default GCC Version


sudo update-alternatives \
     --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 \      --slave /usr/bin/g++ g++ /usr/bin/g++-4.8 \      --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-4.8 \      --slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-4.8 \      --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-4.8

Check GCC version again


$ gcc --version<
gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.





No comments:

Post a Comment