Solemnly declare: This article is written by the author based on my personal understanding. errors are inevitable. Please be prepared!
You can reprint, modify, and indicate the source when reprinting!
System Environment
Operating System: Ubuntu 10.04 LTS-Lucid lynx
Kernel version: 2.6.35-32-generic i686 GNU/Linux
System GCC version: GCC (Ubuntu/linaro 4.4.4-14ubuntu5. 1) 4.4.5
I. Preparations
Three software packages are required for GCC Compilation: GMP, mpfr, and MPC. We recommend that you install these three packages first because the following error may occur when using./configure Configuration:
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
1.1 install GMP
Since both mpfr and nmpc depend on GMP packages, GMP is installed first.
$ tar -xvf gmp-5.0.5.tar.bz2
Suggestion: in Linux manual compilation software, to develop build directory build good habits, so create a gmp-5.0.5-build directory
1 $ mkdir gmp-5.0.5-build2 $ CD gmp-5.0.5-build3 $. /.. /gmp-5.0.5/configure (you can use the configuration parameter -- prefix = to specify the installation location, where the default/usr/local/include and/usr/local/lib are used) 4 $ make5 $ make check (this step is used to ensure correct compilation) 6 $ sudo make install
If an error is prompted during configure execution:
checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin
We also need to install the M4 library.
1 $ tar-xvf m4-1.4.16.tar.bz22 $ mkdir m4-1.4.16-build3 $ CD m4-1.4.16-build4 $. /.. /m4-1.4.16-build/configure5 $ make6 $ make check7 $ sudo make install8 $ man M4 (if man M4 can be successful, it indicates that this library has been installed successfully)
After installing M4, we continue to go back to the previous gmp-5.0.5-build directory and continue the configure operation.
Check whether GMP has been installed successfully:
$ ls /usr/local/lib/libgmp*
If the following message is displayed, the operation is successful:
/usr/local/lib/libgmp.a /usr/local/lib/libgmp.so.10/usr/local/lib/libgmp.la /usr/local/lib/libgmp.so.10.0.5/usr/local/lib/libgmp.so
1.2 install mpfr
1 $ tar-xvf mpfr-3.1.12 $ mkdir mpfr-3.1.1-build3 $ CD mpfr-3.1.1-build4 $. /.. /mpfr-3.1.1/configure -- With-GMP-include =/usr/local/include -- With-GMP-Lib =/usr/local/lib 5 (since mpfr depends on this GMP library, therefore, in configure, you must set the location of the GMP library for use when installing the mpfr library .) 6 $ make7 $ make check8 $ sudo make install
1.3 install MCM
1 $ tar -xvf mpc-1.0.12 $ mkdir mpc-1.0.1-build3 $ cd mpc-1.0.1-build4 $ ./../mpc-1.0.1/configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/loca/lib5 $ make6 $ make check7 $ sudo make install
1.4 set Environment Variables
After all the required libraries are installed, check whether the library location is in the LD_LIBRARY_PATH environment variable to prevent the three libraries from being found during GCC compilation.
$ echo $LD_LIBRARY_PATH
If not, manually add
1.4.1 interim measures
$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
1.4.2 permanent solution
You can modify/etc/bashprofile or/etc/profile to stop setting for future use. Global variables are modified here, which are valid for all users,
Modify ~ /. Bashprofile and ~ /. Profile can modify the global variables of the user.
$ sudo vim /etc/profile
Add the following two sentences at the end of the file:
export LD_LIBRARY_PATH=/usr/local/libLD_LIBRARYPATH=:/usr/local/gcc-4.7.2/lib:$LD_LIBRARYPATH
Save and exit
$ source /etc/profile
Ii. Start to install gcc
$ Tar-xvf 4.7.2.tar.bz2 $ mkdir gcc-4.7.2-build $ CD gcc-4.7.2-build $ .. /gcc-4.7.2/configure -- prefix =/usr/local/gcc-4.7.2 -- enable-threads = POSIX -- disable-checking -- enable-classes ages = C, C ++, objc (go to http://gcc.gnu.org/install/configure.html for details) $ make
If an error occurs:
gengtype.c:923: undefined reference to `lexer_line'
Solution:
1 $ sudo apt-Get install build-essential bison flex2 $ make clean (clear files not compiled before) 3 $ make (continue make)
Also encountered an error:
gengtype.c:923: undefined reference to `lexer_line'
View config. log in the build directory (it is really useful to view logs !), Problem Found: conftest. C: 10: Fatal error: ppl_c.h: no such file or directory
Install the PPL and cloog libraries.
1 $ sudo apt-get install libppl0.10-dev2 $ sudo apt-get install libcloog-ppl-dev
After:
1 $ make distclean (you can check the difference between make clean and make distclean on the Internet) 2 $ make3 $ make check (for the sake of insurance)
An error is returned:/bin/Bash: autogen: The command is not found.
You need to install the autogen library!
1 $ sudo apt-Get install autogen2 $ make check)
It's okay. Then we
1 $ sudo make install
3. Set links for GCC
We can use gcc-version to check whether the version is the original gcc4.4 and does not have gcc4.7.2. This is because the executable file of gcc4.7.2 has not been added to the search command path,
So we need to manually add.
3.1 Add the executable files of the new GCC version to the command search path
1 $ which GCC (first use the which command to check the GCC under which path the system calls when using gcc) 2 $/usr/bin/GCC (my display is like this, the GCC command calls the GCC in this path)
Therefore, we need to use the ln command to establish a link so that/usr/bin/GCC points to the GCC under our installation directory. because my previous/usr/bin/GCC has pointed to gcc4.4.
1 $ sudo RM/usr/bin/GCC (delete this link) 2 $ sudo ln-S/usr/local/gcc-4.7.2/bin/GCC/usr/bin/GCC (GCC uses soft link to gcc4.7.2) 3 $ GCC -- version (check the GCC version to see if it is successful !)
As shown in the following figure, the operation is successful:
$ GCC (GCC) 4.7.2 copyright 2012 Free Software Foundation, Inc. This program is free software. Please refer to the source code copyright statement. This software does not have any warranty, including non-marketable and non-applicable warranties for a specific purpose.
3.2 re-link g ++ in the same way to use g ++ 4.7.2!
1 $ which g++2 $ /usr/bin/g++3 $ sudo rm /usr/bin/g++4 $ sudo ln -s /usr/loca/gcc-4.7.2/bin/g++ /usr/bin/g++5 $ g++ -version
As shown in the following figure, the operation is successful:
$ G ++ (GCC) 4.7.2 copyright 2012 Free Software Foundation, Inc. This program is free software. Please refer to the source code copyright statement. This software does not have any warranty, including non-marketable and non-applicable warranties for a specific purpose.
4. Compile a small program and use GCC to test it!