Preface:
The last time I upgraded GCC 4.7.2 on CentOS 6 (), many things have not been studied due to my limited capabilities and time constraints, as a result, there are some redundant and incorrect or uncommonly used parts in the tutorial. (I was also told by my sister that I misled her, so I am wronged.) I apologize to everyone.
This time I updated gcc on Ubuntu 12.04 LTS 64-bit edition and found some original problems. This time I had no time for pressure. I carefully reviewed the official documentation, I also referred to some online posts to gain a deeper understanding of the differences and commonalities in the entire upgrade process, including the installation of dependent packages, different Linux genres, 32-bit and 64-bit.
The following is a summary:
PS: it is shameful to repost without marking the source.
(I have compiled the shell commands in Ubuntu 12.04. If you are very busy, you can just copy and execute the shell code)
Basic Process:
Here is an overview of the entire process, so that everyone can be aware of everything.
1. Install dependency libraries and tools
According to the official documentation, there are not many libraries and tools required for compiling and installation, rather than modifying gcc.
There are two points to emphasize:
1) A c ++ compiler is required. That is to say, if only gcc is used without g ++, this compilation cannot be completed;
2) If you want to compile a 32-bit program on a 64-bit system, you need to install the corresponding Library (enabled by default ).
2. configure (configure)
Configure the languages supported by the gcc compiled by us, the target environment (whether it is a cross compiler), and the dependent library path (which can be omitted under certain conditions for details ), where to install the compilation result ...... The configuration program will generate the Makefile file based on the information for future use.
3. Compile (make)
Compile gcc and corresponding lib, such as libstdc ++, based on the Makefile generated by configure.
Process:
Please read more official documents: http://gcc.gnu.org/install/
1. Install dependency libraries and tools
Tools:
Supports c ++ 98 compilers (g ++), make, perl, decompression tools (tar, gzip, etc.), and Binutils (only required in some cases.
Generally, you don't need to worry too much here, because most of the tools in linux are in place after the installation is complete. The only thing you need to note is the c/c ++ environment.
If gcc and g ++ are installed on the local machine, skip this part.
Unbutu can be used:
Apt-get install build-essential
And install other required libraries such as glibc (libc in Ubuntu ).
Some other Linux platforms do not have the build-essential package, which is a little troublesome.
Because g ++ and gcc are installed, libstdc ++ and glibc must be installed. Therefore, we recommend that you use:
Apt-get install gcc g + + make libc6-dev
To avoid some disgusting problems, you can also ensure that the corresponding tool is installed.
Library:
According to the official documentation, if only the installation is not modified, only five dependent third-party libraries are required.
These five databases are divided into two categories. One Class (gmp, MCM, mpfr) can be automatically compiled during the gcc compilation process (the source code is downloaded and correctly placed first ), the other is the isl and cloog that need to be installed independently ).
Operation:
1. Check whether they have been installed:
If you want to check whether the XXX library is installed, use:
Locate libXXX
If you find the libXXX. so file, it indicates that the library has been installed. (For more information about database search paths, see)
2. Installation (if you find that a library has been installed, you do not need to install it again ):
For the three libraries of gmp, mpc, and mpfr, you can run the command in the gcc root directory.
./Contrib/download_prerequisites
Download and decompress the package, and create a symbolic connection. (If the download speed is slow, you can modify the version number in the script to other gnu images. Note that modifying the version number will not cause other problems according to the instructions on the official website)
According to the gcc compilation rules: If the gcc root directory contains the gmp, nmpc, and mpfr directories, they will automatically make and do not need to be manually installed when making gcc.
For the isl and cloog libraries, You can compile them by yourself (please read the official documentation for details during compilation), but we recommend that you download them directly from the source. (Cloog depends on gmp and isl, which means it will be very troublesome to compile .)
For example:
Apt-get intall libisl-dev libcloog-isl3
In a specific environment, you may need to modify the library name. You can click the Tab key twice after entering libisl or libcloog.
3. install other libraries:
If you want to compile a 32-bit program in a 64-bit system, a 32-bit Runtime Library is required, which is not installed by default in a 64-bit system.
Ubuntu has a simple method, which can be used:
Apt-get install gcc-multilib g ++-multilib
Fedora can be used as follows:
Apt-get install glibc-devel.i686 libstdc ++-devel. i686
You can also use this mode in Ubuntu to modify the package name to install the corresponding package.