Redhat5.5 upgrade installation GCC-4.6.1 detailed tutorial

Source: Internet
Author: User
Tags gmp

1. What is GCC?

In Linux, GCC (gnu c compiler) is a powerful and superior multi-platform compiler launched by GNU. It is one of the representative works of GNU. GCC can compile and execute on multiple hardware platformsProgramThe execution efficiency of the Super compiler is 20% higher than the average efficiency of the general compiler ~ 30%.

The GCC compiler can compile and connect the C and C ++ language source programs, programming sequences, and target programs into executable files. if the name of the executable file is not given, GCC will generate. out file. In Linux, the executable file does not have a uniform suffix. The system distinguishes the executable file from the unexecutable File Based on the file attributes.

Ii. Some agreed rules of GCC The problem of cheap suffixes is mentioned earlier, while GCC uses suffixes to differentiate the categories of input files. Next we will introduce some agreed rules that GCC follows. . C is a suffix file, C LanguageSource codeFile; . A is a file with a suffix. It is a file library consisting of the target file;
. C or. cc or. cxx is a C ++ source.CodeFile; . H is a suffix file, which is the header file included by the program; . I is a file with a suffix. It is a pre-processed C source code file; . II is a file with a suffix. It is a pre-processed C ++ source code file; . M is a suffix file, which is an objective-C source code file; The. o file is the compiled target file; . S is a suffix file, which is an assembly language source code file; . S is a precompiled assembly language source code file. Iii. GCC Execution Process Although we call gcc a c language compiler, the process of using GCC to generate executable files from C language source code files is not just a compilation process, instead, we need to go through four interrelated steps: preprocessing (also called preprocessing), compilation, assembly, and linking ). ● The command GCC first calls CPP for preprocessing. During the preprocessing process, it analyzes the file inclusion (include) and pre-compiled statements (such as macro definition define) in the source code file. ● Next, you can call the code to compile the object. In this stage, a target file with the. O suffix is generated based on the input file. The assembly process is a step for the assembly language and calls as for work. Generally ,. S is the suffix of the assembly language source code file and assembly ,. the assembly language files suffixed with S are generated after pre-compilation and assembly. O is the target file with the suffix. ● When all target files are generated, GCC calls LD to complete the final key work. This stage is the connection. During the connection phase, all target files are arranged in the proper location of the executable program. At the same time, the library functions called by this program are also connected to appropriate places from their respective archives. Iv. Basic GCC usage and options When using the GCC compiler, we must provide a series of necessary call parameters and file names. The GCC compiler has more than 100 calling parameters, most of which may not be used at all. Here we only introduce the most basic and commonly used parameters. The most basic usage of GCC is: GCC [Options] [filenames], where options is the parameter required by the compiler, and filenames provides the relevant file name. 5. GCC Parameter options -C: only compiled, not connected to executable files, the compiler is only input. C and other source code file generation. O is a target file with a suffix. It is usually used to compile a subroutine file that does not contain the main program. -O output_filename: Make sure the output file name is output_filename. The name cannot be the same as the source file name. If this option is not provided, GCC provides the preset Executable File A. Out. -G, generate the symbolic information necessary for the symbolic debugging tool (gnu gdb). To debug the source code, we must add this option. -O: optimizes compilation and connection of programs. With this option, the entire source code is optimized during compilation and connection. This improves the execution efficiency of executable files, however, the compilation and connection speed is correspondingly slower. -O2: it is better to optimize compilation and connection than-o. Of course, the entire compilation and connection process will be slower.
-Idirname: add the directory specified by dirname to the program header file directory list, which is a parameter used during the pre-compilation process. Vi. GCC Installation Method Running Environment: VMware Workstation 7.1.2 build-301548
Linux: Red Hat Enterprise Linux 5.5
Kernel version: Linux kernel 2.6.18-194. EL5 #1 SMP Tue Mar 16 21:52:43 EDT 2010 i686 i686 i386 GNU/Linux
Note: Due to WordPress escape, the following -- translated as-may be caused. During the experiment, do not copy the above Code.
Manually write data, such as prefix, with-GMP, with-mpfr, and with-MPC-

1. Download the installation package for gcc-4.6.1
GCC versions browse address: http://ftp.gnu.org/gnu/gcc/
Gcc-4.6.1 address: http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/
Gcc-4.6.1: http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.bz2
2.put gcc-4.6.1.tar.bz2 in the/OPT folder and decompress it.
Root@rekfan.com ~ # CD/OPT
[Root@rekfan.com opt] # Tar xjvf gcc-4.6.1.tar.bz2
3. Create an installation directory
[Root@rekfan.com opt] # Mkdir/usr/local/gcc-4.6.1/
4. Go to the installation directory
[Root@rekfan.com opt] # CD/usr/local/gcc-4.6.1/
5. Configure the Installation File
[Root@rekfan.com gcc-4.6.1] # /Opt/gcc-4.6.1/configure -- prefix =/usr/local/gcc-4.6.1
(Execute the configure command in the source directory/opt/gcc-4.6.1/and configure to install GCC under the target directory/usr/local/gcc-4.6.1, here-the prefix option indicates where to install the library, which will be used for later installation if I install it in the/usr/local/gcc-4.6.1 directory)

If the following error occurs during this step:
----------------------------------------------------------------------------------
[Root@rekfan.com gcc-4.6.1] #/opt/gcc-4.6.1/configure -- prefix =/usr/local/gcc-4.6.1/
Checking build system type... I686-pc-linux-gnu
Checking host system type... I686-pc-linux-gnu
Checking target system type... I686-pc-linux-gnu
Checking for a BSD-compatible install... /Usr/bin/install-C
Checking whether ln works... Yes
Checking whether ln-s works... Yes
Checking for a sed that does not truncate output... /Bin/SED
Checking for gawk... Gawk
Checking for GCC... No
Checking for CC... No
Checking for cl.exe... No
Configure: Error: In '/usr/local/gcc-4.6.1 ':
Configure: Error: no acceptable C compiler found in $ path

See 'config. log' for more details.
----------------------------------------------------------------------------------
The above error indicates that the C compiler is not found in $ path.
If the system has a GCC compiler, set the environment variable.
For example:
Export Path = $ path:/usr/local/bin
If not, install the RPM package of lower GCC versions first.
Insert a Linux software disk (usually the first or second disk), mount the disk, and install the disk in sequence as follows:

[root@rekfan.com opt] # rpm-IVH cpp-4.1.2-48.el5.i386.rpm
[root@rekfan.com opt ] # rpm-IVH kernel-headers-2.6.18-194.el5.i386.rpm
[root@rekfan.com opt ] # rpm-IVH glibc-headers-2.5-49.i386.rpm
[root@rekfan.com opt ] # rpm-IVH glibc-devel-2.5-49.i386.rpm
[root@rekfan.com opt ] # rpm-IVH libgomp-4.4.0-6.el5.i386.rpm
[root@rekfan.com opt ] # rpm-IVH gcc-4.1.2-48.el5.i386.rpm

Repeat Step 5 and there is a new error. Below are some error codes! If there are no errors, go directly to Step 7!
----------------------------------------------------------------------------------
Configure: Error: Building GCC requires GMP 4.2 +, mpfr 2.3.1 + and MCM 0.8.0 +.
Try the -- with-GMP, -- With-mpfr and/or -- With-MPC options to specify
Their locations.
----------------------------------------------------------------------------------

Error Description: To install GCC, you need three libraries: GMP, mpfr, and MCM. Ftp://gcc.gnu.org/pub/gcc/infrastructure/ Download the corresponding compressed package. 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. The three libraries I used here are gmp4.3.2, mpfr2.4.2, and mpc0.8.1 IN THE/OPT folder.
①. Install gmp4.3.2
[Root@rekfan.com opt] # tar jxvf gmp-4.3.2.tar.bz2
[Root@rekfan.com opt] # mkdir/usr/local/gmp-4.3.2
[Root@rekfan.com opt] # cd/usr/local/gmp-4.3.2
[Root@rekfan.com gmp-4.3.2] # /Opt/gmp-4.3.2/configure -- prefix =/usr/local/gmp-4.3.2
[Root@rekfan.com gmp-4.3.2] # Make)
[Root@rekfan.com gmp-4.3.2] # make install (for installation)
② Install mpfr2.4.2
[Root@rekfan.com opt] # tar jxvf mpfr2.4.2.tar.bz2
[Root@rekfan.com opt] # mkdir/usr/local/mpfr-2.4.2
[Root@rekfan.com opt] # cd/usr/local/mpfr-2.4.2
[Root@rekfan.com mpfr-2.4.2] # /Opt/mpfr-2.4.2/configure -- prefix =/usr/local/mpfr-2.4.2-with-GMP =/usr/local/gmp-4.3.2
(Note that the dependency option should be added during configuration)
Root@rekfan.com mpfr-2.4.2 # Make
[Root@rekfan.com mpfr-2.4.2] # make install
③ Install mpc0.8.1
[Root@rekfan.com opt] # tar jxvf gmpc0.8.1.tar.bz2
[Root@rekfan.com opt] # mkdir/usr/local/mpc-0.8.1
[Root@rekfan.com opt] # cd/usr/local/mpc-0.8.1
[Root@rekfan.com mpc-0.8.1] # /Opt/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
Root@rekfan.com mpc-0.8.1 # Make
[Root@rekfan.com mpc-0.8.1] # make install
④ Re-install GCC configuration and installation options
[Root@rekfan.com mpc-0.8.1] # cd/usr/local/gcc-4.6.1
[Root@rekfan.com gcc-4.6.1] #/Opt/gcc-4.6.1/configure -- prefix =/usr/local/gcc-4.6.1-enable-threads = POSIX-Disable-checking-Disable-multilib-enable-versions ages = 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

6. Compile the Installation File
[Root@rekfan.com gcc-4.6.1] # Make
It may take about 1 hour to have a coffee cup. Please wait!
An hour later ···
The second error occurs:

open/usr/local/gcc-4.6.1/i686-pc-linux-gnu/libgcc/config. log
Ctrl + F find error found the following error
/----------------------------------------------------------------------------
/usr/local/gcc-4.6.1 /. /GCC/PC3: Error while loading shared libraries: libmp C. so.2: cannot open shared object file: no such file or directory
Configure: 3058 :$? = 1
environment/
the solution is found on the Internet. You need to add the environment variable LD_LIBRARY_PATH to indicate the location of the first three databases. type the following command:
[root@rekfan.com gcc-4.6.1] # export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH: /usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib: /usr/local/mpfr-2.4.2/lib
execute step 6 again →
about three hours later ·
finally compiled successfully, enter:

7. Install gcc
[Root@rekfan.com gcc-4.6.1] # Make install
[Root@rekfan.com gcc-4.6.1] #
If there is no accident, the installation should be successful now, but the new version of GCC cannot be used, because the new version of GCC has not been added to the command search path!
8. Create a soft link
Root@rekfan.com/] #Sudo ln-S/usr/local/gcc-4.6.1/bin/GCC gcc461
Root@rekfan.com/] #Sudo ln-S/usr/local/gcc-4.6.1/bin/g ++ 461
9. Add Environment Variables
Open the bashrc file in the/etc directory and add the following code:
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.6.1/lib

Export LD_LIBRARY_PATH

 

 

 

 

 

 

 

 

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.