As we all know: Although CentOS is easy to use, its own yum source is very small and lagging behind. Installation Tools often need to download the source code for compilation by themselves. (It seems that rpm with the same el version in the RedHat and Fedora sources can also be used, but it has not been tried)
Other tools are too slow. The most difficult thing to recognize is that their gcc version lags so far. The latest CentOS version () is 6.3, the latest gcc version on the official source is 4.4.6! Now the latest stable gcc version is 4.7.2, and the development version has reached 4.8!
Anyone who knows about c ++ knows that the upgrade time of this version is just a period when various compilers want the c ++ 11 standard to rapidly approaching, it is also a time when more and more people use the c ++ 11 feature. Therefore, upgrading a more functional gcc is not enough.
Now, we have finished talking about The importance. Let's start talking about the business.
The main environment is CentOS 6.3. Use the default gcc 4.4.6 and compile and install gcc 4.8.0.
The steps for upgrading and compiling gcc on the Internet are complicated. I will not talk about the painful process. I just want to talk about it. In fact, it can be very simple.
The first is the dependent library. The official documents said that gmp, mpc, and mpfr are required, and many tutorials have mentioned self-Compiling and installation, as well as some problems in this process, in fact, this is not necessary. Have you ever wondered whether gcc, as a well-developed project with many years of development, has not provided some automated solutions?
Step 1:
Yum install glibc-static libstdc ++-static-y
Install the static libraries of c and c ++ (it is said that if the system lacks libc. a And libstdc ++. a may encounter errors during compilation, but I don't have much fun to try it out. Some practical friends can reply and share their experiences, so that everyone can have a long experience)
Step 2:
Download unzip gcc, my gcc directory is gcc-4.8.0
Step 3:
Go to the gcc directory and run:
./Contrib/download_prerequisites
This magical script file will help us download, configure, and install the three dependent libraries. It saves us a lot of time and energy.
Step 4:
Do you think the three libraries are automatically downloaded and automatically make install is okay? Error!
Many people encounter various strange errors when compiling gcc, that is, this step is not done well.
They are not in the search path of the. so file and need to be added. Remember to execute ldconfig.
The general practice is:
1. Find the directory to which your shared library file is installed (updatedb + locate command ).
2. If your library is not directly stored in/lib or/usr/lib, You need to modify the/etc/ld. so. conf file and add it to the path of your shared library.
3. If the shared library path is added to 2, perform ldconfig to update the response cache file so that the system can find your shared library.
See my previous blog article "Linux shared library path configuration" http://blog.csdn.net/yanxiangtianji/article/details/8316562
Step 5:
Create a temporary directory to store a large number of temporary files during compilation, which is required in document requirements.
I created a directory named gcc-4.8.0 under the gcc-build-4.8.0 and went into it.
Mkdir gcc-build-4.8.0
Cd gcc-build-4.8.0
Configure gcc compilation options
Strongly recommended reading the instructions in the installobject directory, especially configure.html, to determine your compilation options.
The more basic options are -- enable-compatible ages, which indicates that you want your gcc to support those languages. -- disable-multilib does not generate a cross compiler that is compiled into executable code on other platforms. -- The compiler generated by disable-checking does not perform additional checks during the compilation process. You can also use -- enable-checking = xxx to add some checks.
What else do you have on the Internet -- with-gmp, -- with-mpfr, -- with-mpc, but if you do well in step 3 or 4, don't configure it, on the contrary, you should be honest. Don't be lucky.
Call the configure file under the gcc-4.8.0 directory:
For example:
../Configure -- enable-checking = release -- enable-extensions ages = c, c ++ -- disable-multilib
Step 7:
Run
../Make # Not explained
Execute the compilation command (# compile on an 8-core virtual machine, and assign 2 compilation tasks to each core)
Make-j16
Make install
During the compilation process, the CPU core is basically 100% occupied, and the total Compilation Time is 11 minutes and 50 seconds.
Check the gcc version
# Wait for a teenager. We recommend that you do this before going to bed at night.
Of course, the above three steps must be carried out when the previous step ends smoothly. If any step has an error, the results will all show an error, so do not proceed with the subsequent steps. Search for "error" in the shell output to see what the specific error points are, baidu and google.
Make check before make install.