Install GCC4.6.2 manually in CentOS 5.5

Source: Internet
Author: User
Tags gmp

Download the latest GCC4.6.2 from the GCC website

Http://gcc.gnu.org/

Domestic image address:
Http://mirrors.ustc.edu.cn/gnu/gcc/

First, an error occurs during gcc Configuration:
#./Configure -- prefix =/usr/local/gcc-4.6.2
Configure: error: Building GCC requires GMP 4.2 +, MPFR 2.3.1 + and MCM 0.8.0 +.
It indicates that the gcc installation requires three libraries: GMP, MPFR, and MCM.
Official Website:
Http://gmplib.org/
Http://www.mpfr.org/
Http://www.multiprecision.org/index.php? Prog = nmpc

Since MPFR depends on GMP, while nmms depends on GMP and MPFR, it is necessary to install GMP first, followed by MPFR, and finally the nmms. Here the three libraries I use are gmp-5.0.3, mpfr-3.1.0, and mpc-0.9.
Decompress the three packages in sequence.

Install gmp-5.0.3
# Cd gmp-5.0.3
#./Configure -- prefix =/usr/local/gmp-5.0.3
# Make & make install & make clean

Install mpfr-3.1.0
# Cd mpfr-3.1.0
#./Configure -- prefix =/usr/local/mpfr-3.1.0 -- with-gmp =/usr/local/gmp-5.0.3
# Make & make install & make clean

Install mpc-0.9
# Cd mpc-0.9
#./Configure -- prefix =/usr/local/mpc-0.9 -- with-gmp =/usr/local/gmp-5.0.3 -- with-mpfr =/usr/local/mpfr-3.1.0
# Make & make install & make clean


After these three libraries are installed, you can officially start to install gcc.
Go to the gcc source code directory
There are many gcc configuration options. For details, refer to the installation instructions under the gcc source file directory. Only the c and c ++ compilers are installed here. (If the compilation language is not specified, it will fail during make, and some files cannot be found and other errors are reported. Therefore, we recommend that you specify the compilation language as c, c ++) then start make compilation. To be safe, you must add the location of the first three libraries in the environment variable LD_LIBRARY_PATH. type the following command:
Export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/mpc-0.9/lib:/usr/local/gmp-5.0.3/lib:/usr/local/mpfr-3.1.0/lib
Then re-make the compilation. After a long wait hour, the compilation is completed.


#. /Configure -- prefix =/usr/local/gcc-4.6.2 -- enable-threads = posix -- disable-checking -- disable-multilib -- enable-versions ages = c, c ++ -- with-gmp =/usr/local/gmp-5.0.3 -- with-mpfr =/usr/local/mpfr-3.1.0 -- with-mpc =/usr/local/mpc-0.9
# Make & make install & make clean


Now all gcc installation is complete.
However, the new version of gcc cannot be used yet, because the new version of executable files have not been added to the command search path. Here I have created a soft link for the new gcc and g ++ commands. Enter the/usr/bin directory and type the following command to create a soft link.


Sudo ln-s/usr/local/gcc-4.6.2/bin/gcc gcc462
Sudo ln-s/usr/local/gcc-4.6.2/bin/g ++ 462
In this way, when using the new version of gcc, I can use the gcc462 and g ++ 462 commands, as well as the original gcc Compilation Program. Of course, you can also directly link the gcc and g ++ commands in the/usr/bin directory to the new version of the gcc executable file. The last thing to do before getting started is to add the path of the previously installed GCC-4.6.2 Library to the environment variable LD_LIBRARY_PATH, or else errors will occur during program compilation.
Export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/gcc-4.6.2/lib


Because the export method fails after restart, You need to edit the bashrc file in the/etc directory to configure the shell environment.
Add the following statement to the file:
LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/mpc-0.9/lib:/usr/local/gmp-5.0.3/lib:/usr/local/mpfr-3.1.0/lib:/usr/local/gcc-4.6.2/lib
Export LD_LIBRARY_PATH


The above method is not good. You can use the following method:
Vi/etc/ld. so. conf
Add
/Usr/local/mpc-0.9/lib
/Usr/local/gmp-5.0.3/lib
/Usr/local/mpfr-3.1.0/lib
/Usr/local/gcc-4.6.2/lib
Save and exit, and then execute ldconfig to make the change take effect.


In addition, the use of gcc-4.6.2 also has the following method:
Back up the original gcc and g ++
# Cp/usr/bin/gcc. bak
# Cp/usr/bin/g ++. bak


Create soft link
# Cd/usr/bin
# Ln-s/usr/local/The gcc-4.6.2/bin/gcc
# Ln-s/usr/local/gcc-4.6.2/bin/g ++

Restore after use

Error handling:
Make Error
Checking for suffix of object files... configure: error: in '/data/src/gcc/gcc-4.6.2/x86_64-unknown-linux-gnu/libgcc ':
Configure: error: cannot compute suffix of object files: cannot compile
See 'config. log' for more details.
Make [2]: *** [configure-stage1-target-libgcc] Error 1
Make [2]: Leaving directory '/data/src/gcc/gcc-4.6.2'
Make [1]: *** [stage1-bubble] Error 2
Make [1]: Leaving directory '/data/src/gcc/gcc-4.6.2'
Make: *** [all] Error 2

The reason is that the newly added library ldconfig is not effective after ld. so. conf is modified.

Recommended reading:

Ubuntu 12.04 embedded cross-compilation environment arm-linux-GCC Build Process Diagram

Install the cross-compiler arm-none-linux-gnueabi-GCC in Ubuntu 12.10

Install and use Vim + GCC + GDB in Ubuntu

Switch two GCC versions in Ubuntu

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.