Manual switching of earlier GCC versions under Ubuntu

Source: Internet
Author: User

GCC is the GNU exclusive C/C ++ compiler. Because GCC has compatibility issues, you must use the specified version of GCC to compile and pass the code, therefore, we should switch to the appropriate GCC compiler in a timely manner.

1. Brief description:
In general, the Compilation Program uses:/usr/bin/GCC

In fact, this/usr/bin/GCC is just a symbolic link, it points to/etc/alternatives/GCC, and/etc/alternatives/GCC is pointing to/usr/bin/gcc-4.4, we can use the LS command to view:
ZYX @ ZYX:/$ ls/usr/bin/GCC-l
Lrwxrwxrwx 1 Root 21/usr/bin/GCC->/etc/alternatives/GCC
ZYX @ ZYX:/$ ls/etc/alternatives/GCC-l
Lrwxrwxrwx 1 Root 16 2011-08-22 07:21/etc/alternatives/GCC->/usr/bin/gcc-3.4
ZYX @ ZYX:/$

2. Now let's take a look at the GCC version:
ZYX @ ZYX:/$ gcc-V
Using built-in specs.
Target: i686-linux-gnu
Configured :.. /src/configure-V -- With-pkgversion = 'ubuntu/linaro 4.4.4-14ubuntu5' -- With-bugurl = file: // usr/share/doc/gcc-4.4/readme. bugs -- enable-languages ages = C, C ++, Fortran, objc, OBJ-C ++ -- prefix =/usr -- Program-suffix =-4.4 -- enable-shared -- enable-multiarch
-- Enable-linker-Build-id -- With-system-zlib -- libexecdir =/usr/lib -- without-included-gettext -- enable-threads = POSIX -- With-gxx-include- dir =/usr/include/C ++/4.4 -- libdir =/usr/lib -- enable-NLS -- With-sysroot =/-- enable-clocale = GNU -- enable-libstdcxx- debug -- enable-objc-GC
-- Enable-targets = all -- disable-werror -- With-arch-32 = i686 -- With-tune = generic -- enable-checking = release -- Build = i686-linux-gnu -- Host = i686-linux-gnu -- Target = i686-linux-gnu
Thread model: POSIX
GCC version 4.4.5 (Ubuntu/linaro 4.4.4-14ubuntu5)
ZYX @ ZYX:/$

3. Check the GCC versions currently installed:
ZYX @ ZYX:/$ ls/usr/bin/GCC *-l
Lrwxrwxrwx 1 Root 21/usr/bin/GCC->/etc/alternatives/GCC
-Rwxr-XR-x 1 Root 85552/usr/bin/gcc-3.4
-Rwxr-XR-x 1 Root 224488 2010-09-28 0:43/usr/bin/gcc-4.4
Lrwxrwxrwx 1 Root 7/usr/bin/GCC. Bak-> gcc-4.4
-Rwxr-XR-x 1 Root 16090/usr/bin/gccbug-3.4
ZYX @ ZYX:/$

We see that the gcc-3.4.x has been installed, as long as you point the Symbolic Link (that is, soft connection) to the gcc-3.4, next we use the update-alternatives tool to change the symbolic link.

1. Install the gcc-3.4.6 and gcc-4.3.2 options separately, using the command below:
ZYX @ ZYX:/$ sudo Update-alternatives -- install/usr/bin/GCC gcc/usr/bin/gcc-3.4 50
[Sudo] password for ZYX:
ZYX @ ZYX:/$ sudo Update-alternatives -- install/usr/bin/GCC/usr/bin/gcc-4.4 60
ZYX @ ZYX:/$
Command Format: sudo Update-alternatives -- install <link> <Name> <path> <priority>

2. Run the following command to switch the GCC compiler:
ZYX @ ZYX:/$ sudo Update-alternatives -- config gcc

The result is:
ZYX @ ZYX:/$ 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.4 60 Auto Mode
1/usr/bin/gcc-3.4 50 manual mode
* 2/usr/bin/gcc-4.4 60 manual mode

Press enter to keep the current choice [*], or type selection number: 1
Update-Alternatives: Using/usr/bin/gcc-3.4 to provide/usr/bin/GCC (GCC) in manual mode.

We entered 1 and chose the compiler of the gcc-3.4 version.

3. Check the switched compiler version:

ZYX @ ZYX:/$ gcc-V
Reading specs from/usr/lib/GCC/i486-linux-gnu/3.4.6/specs
Configured :.. /src/configure-V -- enable-ages = C, C ++, f77, pascal -- prefix =/usr -- libexecdir =/usr/lib -- With-gxx-include-Dir =/usr/include/C ++/3.4 -- enable-shared -- With-System -zlib -- enable-NLS -- without-receivded-gettext -- Program-suffix =-3.4 -- enable-_ cxa_atexit
-- Enable-clocale = GNU -- enable-libstdcxx-Debug -- With-tune = pentium4 i486-linux-gnu
Thread model: POSIX
GCC version 3.4.6 (Ubuntu 3.4.6-6ubuntu5)
ZYX @ ZYX:/$

OK !! You have switched over.

Next we will introduce a simple method to switch the compiler version:

First, delete the GCC file in the usr/bin/directory or rename it GCC. Bak. If you do not delete it, you may find that using ln-S/usr/bin/gcc-3.4/usr/bin/GCC always does not work.
The procedure is as follows:

ZYX @ ZYX:/$ sudo mV/usr/bin/GCC. Bak
[Sudo] password for ZYX:
ZYX @ ZYX:/$ sudo ln-S/usr/bin/gcc-4.4/usr/bin/GCC
ZYX @ ZYX:/$ gcc-V
Using built-in specs.
Target: i686-linux-gnu
Configured :.. /src/configure-V -- With-pkgversion = 'ubuntu/linaro 4.4.4-14ubuntu5' -- With-bugurl = file: // usr/share/doc/gcc-4.4/readme. bugs -- enable-languages ages = C, C ++, Fortran, objc, OBJ-C ++ -- prefix =/usr -- Program-suffix =-4.4 -- enable-shared -- enable-multiarch
-- Enable-linker-Build-id -- With-system-zlib -- libexecdir =/usr/lib -- without-included-gettext -- enable-threads = POSIX -- With-gxx-include- dir =/usr/include/C ++/4.4 -- libdir =/usr/lib -- enable-NLS -- With-sysroot =/-- enable-clocale = GNU -- enable-libstdcxx- debug -- enable-objc-GC
-- Enable-targets = all -- disable-werror -- With-arch-32 = i686 -- With-tune = generic -- enable-checking = release -- Build = i686-linux-gnu -- Host = i686-linux-gnu -- Target = i686-linux-gnu
Thread model: POSIX
GCC version 4.4.5 (Ubuntu/linaro 4.4.4-14ubuntu5)
ZYX @ ZYX:/$

Now we have switched over. If you run LS-La/bin/sh to see that the link is Dash, run the following command sudo dpkg-reconfigure Dash and select no to delete dash, after compilation is complete, run the command again. Select Yes to reinstall dash. If no change is made, an error will occur during compilation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.