preparatory work
Download and unzip the GCC source pack
Download a GCC source package from HTTP://FTP.GNU.ORG/GNU/GCC that you want to compile. For example, download is gcc-4.7.2.tar.bz2, and then use the input decompression command TAR-XVF 4.7.2.tar.bz2
To install the required libraries
When you use the./configure configuration, you may experience the following error: Configure:error:Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
This indicates the need to use the GMP MPFRMPC these three libraries. Delivery door: GMP download MPFR download MPC download
Because MPFR and MPC are dependent on GMP package, so first install GMP.
$ TAR-XVF gmp-5.0.5.tar.bz2
when manually compiling software under Linux, make it a good habit of building a build directory, so create a gmp-5.0.5-build directory
$ mkdir Gmp-5.0.5-build
$ CD Gmp-5.0.5-build
$./.. /gmp-5.0.5/configure (You can use the configuration parameter--prefix= specify the installation location, where default/usr/local/include and/usr/local/lib are used)
$make
$make check (This step is used to ensure that the compilation is correct)
$sudo make Install
Error may be prompted when executing configure: Checking for suitable M4 ... configure:error:No usable M4 in $PATH Or/usr/5bin
This means we also have to install M4 this library, Portal: M4
$ TAR-XVF m4-1.4.16.tar.bz2
$ mkdir M4-1.4.16-build
$ CD M4-1.4.16-build
$ ./.. /m4-1.4.16-build/configure
$ make
$ make Check
$ sudo make install
$ man M4 (if you can succeed man M4, this library is installed successfully)
After installing M4, we continue to go back to the Gmp-5.0.5-build directory and continue with the configure operation.
Then install MPFR this library
$ TAR-XVF mpfr-3.1.1
$ mkdir Mpfr-3.1.1-build
$ CD Mpfr-3.1.1-build
$ ./.. /mpfr-3.1.1/configure--with-gmp-include=/usr/local/include--with-gmp-lib=/usr/local/lib (because MPFR relies on GMP for this library, So in configure, you need to set up the GMP library location, for the installation of MPFR library use. )
$ make
$ make Check
$ sudo make install
Then install the MPC Library
$ TAR-XVF mpc-1.0.1
$ mkdir Mpc-1.0.1-build
$ CD Mpc-1.0.1-build
$ ./.. /mpc-1.0.1/configure--with-gmp-include=/usr/local/include--with-gmp-lib=/usr/loca/lib
$ make
$ make Check
$ sudo make install
After the required libraries are installed, to prevent the compilation of GCC from finding these three libraries, you need to confirm that the library location is ld_library_path in the environment variable
$ echo $LD _library_path
If not, add them manually
$ export ld_library_path= "$LD _library_path:/usr/local/lib"
For later use, we can modify/etc/bashprofile or/etc/profile. This modifies the global variable, which is valid for all users, and modifies ~/.bashprofile and ~/.profile to modify the user's global variables.
$ sudo vim/etc/profile
Add the following two sentences:
Export Ld_library_path=/usr/local/lib
Ld_librarypath=:/usr/local/gcc-4.7.2/lib: $LD _librarypath
Save exit
$ souce/etc/profile
Once you've done this, you're ready to start compiling gcc.
Build directory, start compiling
$ mkdir Gcc-4.7.2-build
$ CD Gcc-4.7.2-build
The next step is to perform a series of configure configurations, and a series of configurations can be seen on the GCC official site (http://gcc.gnu.org/install/configure.html). I was compiling a reference to the original configuration of my machine made a little bit of change.
I use it under my terminal.
$ gcc-v
Some column information appears: Target:i686-linux-gnu configured with:. /src/configure-v--with-pkgversion= ' Ubuntu/linaro 4.4.4-14ubuntu5.1 '--with-bugurl=file:///usr/share/doc/gcc-4.4/ Readme. Bugs--enable-languages=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.1)
There are a lot of configuration, I picked a few, and finally use the Configure configuration as follows:
$ .. /gcc-4.7.2/configure--prefix=/usr/local/gcc-4.7.2--enable-threads=posix--disable-checking--enable-languages=c, C++,OBJC (or--enable-threads=posix--disable-checking--disable-multilib--enable-languages=c,c++)
Then execute make
$ make
Result encountered error: gengtype.c:923:undefined reference to ' Lexer_line '
Install some tools and build environments on the Web: Build-essential Bison Flex
Originally wanted to install an X, with the source of the installation of GCC, did not expect to rely on the powerful Apt-get:(
$ sudo apt-get install Build-essential Bison Flex
$ make clean (erase files that were not successfully compiled before)
$ make (Continue make)
Also encountered error: gengtype.c:923:undefined reference to ' Lexer_line '
Look at the Config.log in the build directory (view log is really useful.) ), Discovery problem: conftest.c:10:fatal error:ppl_c.h:no such file or directory
Internet access to information, you need to install the PPL and Cloog library. Here is the introduction: Portal
(= = Forgive me for using apt-get again)
$ sudo apt-get install Libppl0.10-dev
$ sudo apt-get install Libcloog-ppl-dev
When it's over:
$ make distclean (makes clean and distclean can be referred to as: portal)
$ make
This time finally made good, there is nothing wrong. To be on the safe side,
$ make Check
Result error:/bin/bash:autogen: Command not found
Check the Internet, Autogen This library is not installed, Ann.
$ sudo apt-get install Autogen
$ make Check
Finally, there is no problem. Then we
$ sudo make install
The step was soon finished. We use Gcc-version to view, the version is the original gcc4.4, and there is no gcc4.7.2, this is because the gcc4.7.2 executable file has not been added to the search command path, so we have to manually join.
-Add the new GCC executable file to the command search path
The first time you use the which command to view GCC when using GCC, what path does the system call?
$ which GCC
$/USR/BIN/GCC (stating that GCC commands call GCC under this path)
To do this, we're going to use the LN command to create a link that lets/USR/BIN/GCC point to GCC under our installation directory. Because my previous/USR/BIN/GCC has pointed to gcc4.4, so delete this link first.
$ sudo rm/usr/bin/gcc
Then, make GCC use soft link to gcc4.7.2
$ sudo ln-s/usr/local/gcc-4.7.2/bin/gcc/usr/bin/gcc
Next, check out the GCC version to see if there is any success.
$ gcc--version
$ gcc (gcc) 4.7.2 copyright©2012 free Software Foundation, Inc. this procedure is freeware; Please refer to the copyright notice of the source code. There is no warranty of this software, including the warranties of merchantability and fitness for a specific purpose.
It worked. We are using the same method to relink the next g++, we can use the g++4.7.2.
$ which g++
$/usr/bin/g++
$ sudo rm/usr/bin/g++
$ sudo ln-s/usr/loca/gcc-4.7.2/bin/g++/usr/bin/g++
$ g++-version
$ g++ (GCC) 4.7.2 copyright©2012 free Software Foundation, Inc. this procedure is freeware; Please refer to the copyright notice of the source code. There is no warranty of this software, including the warranties of merchantability and fitness for a specific purpose.
Finally, write a small program, use GCC to test it.
another article:
First, an error occurs during the configuration of gcc: gcc configure:error:Building gcc requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+
Description to install GCC requires GMP, MPFR, MPC three libraries, can download the corresponding compression package from the ftp://gcc.gnu.org/pub/gcc/infrastructure/. Because MPFR rely on GMP, and the MPC relies on GMP and MPFR, so first install GMP, followed by MPFR, the final is the MPC. The three libraries I use here are gmp4.3.2,mpfr2.4.2 and mpc0.8.1 respectively.
Start to install GMP first. Extract the GMP compression package, get the source code directory gmp-4.3.2. Create a temporary compilation directory in the same directory, named Gmp-build. Then start configuring the installation option, enter the Gmp-build directory, and enter the following command to configure:
.. /gmp-4.3.2/configure--prefix=/usr/local/gmp-4.3.2
Here the--prefix option represents where to install the library, I am installed in the/usr/local/gmp-4.3.2 directory, and this option is used for subsequent installations.
At this time in the GMP compiled directory will generate a makefile file, now start compiling the installation.
Make
Make check
sudo make install
This is the installation of GMP. The MPFR and MPC installation methods are similar. However, to be aware of the configuration to add dependency options, the following two library configuration commands are as follows:
.. /mpfr-2.4.2/configure--prefix=/usr/local/mpfr-2.4.2--with-gmp=/usr/local/gmp-4.3.2
.. /mpc-0.8.1/configure--prefix=/usr/local/mpc-0.8.1--with-gmp=/usr/local/gmp-4.3.2--with-mpfr=/usr/local/ mpfr-2.4.2
Once you have installed these three libraries, you are ready to start installing GCC.
As before, build a temporary directory Gcc-build to compile GCC, and then configure installation options after entering the directory:
.. /gcc-4.4.3/configure--prefix=/usr/local/gcc-4.4.3--enable-threads=posix--disable-checking--disable-multilib-- enable-languages=c,c++--with-gmp=/usr/local/gmp-4.3.2--with-mpfr=/usr/local/mpfr-2.4.2--with-mpc=/usr/local/ mpc-0.8.1
There are many configuration options for GCC, and you can refer to the installation instructions in the GCC source files directory. Only the C and C + + compilers are installed here. (If you do not specify a compiled language, you do not pass at make, and some files cannot be found, and so on, it is recommended that you specify the compiled language as c,c++) and start make compilation. For insurance purposes, you need to add the previous three libraries to the environment variable ld_library_path, and type the following command:
Export Ld_library_path= $LD _library_path:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-2.4.2 /lib
Then make the compilation again, after a long 1-hour wait, finally compile the completion. There is also a test step in the installation instructions, but that is optional. Direct make install installation, so GCC is fully installed. However, the new version of GCC is not available at this time because the newer executable file is not yet added to the search path for the command. Here I set up a soft link for the new GCC and g++ commands, respectively. After entering the/usr/bin directory, type the following command to establish a soft link.
sudo ln-s/usr/local/gcc-4.4.3/bin/gcc gcc44
sudo ln-s/usr/local/gcc-4.4.3/bin/g++ g++44
This allows me to use the GCC44 and G++44 commands when using the new version of GCC, and to compile the program using the original GCC. Of course, you can also link the/usr/bin directory gcc,g++ command back to the new version of the GCC executable. The last thing to do before the formal use is to add the path of the three libraries that were previously installed to the environment variable ld_library_path, or you will get an error when compiling the program. Since I don't want to generate environment variables every time I compile the program, I need to edit the BASHRC file in the/ETC directory to configure the shell environment. Add the following statement to this file:
ld_library_path=:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/ Gcc-4.4.3/lib
Export Ld_library_path
After you save the reboot system, you can use the new installed GCC.
The above is the whole process that I install gcc4.4.3 in CentOS 5.5.
If there is an error there may be no link library
sudo ln-s/usr/local/lib/libgmp.so.10/usr/lib/libgmp.so.10
sudo ln-s/usr/local/lib/libmpfr.so.4/usr/lib/libmpfr.so.4
sudo ln-s/usr/local/lib/libmpc.so.3/usr/lib/libmpc.so.3
When problem make comes up with the following prompts:
Checking for suffix of object files ... configure:error:in '/HOME/WULEI/SOURCECODE/GCC-4.6.2/I686-PC-LINUX-GNU/LIBGCC ' :
Configure:error:cannot compute suffix of object Files:cannot compile
"Config.log ' for more details."
MAKE[2]: * * * [CONFIGURE-STAGE1-TARGET-LIBGCC] Error 1
MAKE[2]: Leaving directory '/home/wulei/sourcecode/gcc-4.6.2 '
MAKE[1]: * * * [stage1-bubble] Error 2
MAKE[1]: Leaving directory '/home/wulei/sourcecode/gcc-4.6.2 '
Make: * * * [ALL] Error 2
So I went into/HOME/WULEI/SOURCECODE/GCC-4.6.2/I686-PC-LINUX-GNU/LIBGCC and looked at the Config.log under this path.
The following error message was found:
/home/wulei/sourcecode/gcc-4.6.2/host-i686-pc-linux-gnu/gcc/cc1:error while loading shared libraries:libmpfr.so.1: Cannot open shared OB ject file:no such file or directory
Find this problem on the Internet
The reason is that Linux does not automatically search for new libraries when made, so you want to add them by command.
Ld_library_path=/usr/local/mpc-0.8.1/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gmp-4.3.2/lib
Echo $LD _library_path
Export $LD _library_path
Reference:
Http://www.comdyn.cn/from-web/68-server-setup/164-centos-48-gcc450.html
My environment: CentOS 6.2, Kernel 3.1.10 x86_64
Required configuration: Disk space >= 6GB, Mem >= 1GB
Download gcc-4.7.2.tar.bz2 from gcc.gnu.org, create the/ROOT/BUID-GCC directory, and all subsequent compilations are in this directory.
Download the following auxiliary installation packages to ftp://gcc.gnu.org/pub/gcc/infrastructure/: gmp-4.3.2.tar.bz2, mpfr-2.4.2.tar.bz2, mpc-0.8.1.tar.gz
Put the above bz2 and GZ ball all in the/ROOT/BUILD-GCC directory.
1. Compile gmp-4.3.2
Expand gmp-4.3.2.tar.bz2:
#tar XF gmp-4.3.2.tar.bz2
# mkdir Gmp-build
#cd Gmp-build
#.. /gmp-4.3.2/configure--prefix=/root/rpmbuild/gmp-build--build=x86_64-linux
Note: The--build=x86_64-linux option is important for x86_64 platforms (such as the one I use), otherwise it is impossible to generate makefile.
After the makefile is generated, the following command is compiled:
#make
#make Check
#make Install
This is the GMP installed to the/root/build-gcc/gmp-build directory, GMP installation is completed,/root/build-gcc/gmp-build directory in the future when the installation of other packages will be passed as parameters.
2. Compile MPFR
#tar XF mpfr-2.4.2.tar.bz2
#mkdir Mpfr-build
#cd Mpfr-build
#.. /mpfr-2.4.2/configure--prefix=/root/build-gcc/mpfr-build/--with-gmp=/root/build-gcc/gmp-build
#make
#make Check
#make Install
3. Compile the MPC
#tar XF mpc-0.8.1.tar.gz
#mkdir Mpc-build
#cd Mpc-build
#.. /mpc-0.8.1/configure--prefix=/root/build-gcc/mpc-build/--with-gmp=/root/build-gcc/gmp-build/--with-mpfr=/root/ build-gcc/mpfr-build/
#make; Make check; Make install
4. Compile GCC
#tar XF gcc-4.7.2.tar.bz2
#mkdir Gcc-build
Set Ld_library_path (optional)
#export ld_library_path= $LD _library_path:/root/build-gcc/mpc-build/lib:/root/build-gcc/mpfr-build/lib:/root/ Build-gcc/gmp-build/lib
Create makefile
#.. /gcc-4.7.2/configure--prefix=/root/build-gcc/gcc-build/--enable-threads=posix--disable-checking-- Disable-multilib--enable-languages=c,c++--with-gmp=/root/build-gcc/gmp-build/--with-mpfr=/root/build-gcc/ mpfr-build/--with-mpc=/root/build-gcc/mpc-build/
Errors that may occur during build:
Some packages are not installed (although the "Development tools" have previously been installed by the command #yum groupinstall "Development tools"), such as PPL and ppl-devel, errors may occur: Configure: Error:cannot compute suffix of object files:cannot compile. View Log discovery Error Record: Conftest.c:10:19:error:ppl_c.h:no such file or directory Conftest.c:16:error: ' Choke ' undeclared (A/US E in this function) Conftest.c:16:error: (each undeclared identifier was reported only once each function it appears in.) Conftest.c:16:error:expected '; ' Before ' me ' These errors can be ordered by:
#yum install PPL ppl-devel
Install the two packages to correct them.
In addition, if the rigorous point, make after should be done make-k check, but make-k check will report the lack of Autogen this command, but the problem is centos difficult to find this autogen, so, sloppy point, make after making directly Install
When make install is complete, the final executable files, such as gcc,g++, will be generated in the/root/build-gcc/gcc-build/bin directory. At this point,/root/build-gcc/gcc-build/bin does not exist in path. This requires that the newly generated GCC be placed in the/usr/bin for "available":
#ln-S/root/build-gcc/gcc-build/bin/gcc/usr/bin/gcc-4.7
#ln-S/root/build-gcc/gcc-build/bin/g++/usr/bin/g++-4.7
Note: The above must be in absolute path.
The gcc-4.7 and g++-4.7 commands can then be programmed http://blog.csdn.net/foreverdengwei/article/details/8691181
Reference information: http://blog.csdn.net/sstower/article/details/5624010
http://guliqun1983.blog.163.com/blog/static/50111685201162821716214/
Http://www.cnblogs.com/chuncn/archive/2010/10/15/1851853.html
Original: http://chenjiajie.org/post/2012-11-25/40042373551