Centos6.5 from the source code compilation and installation of GCC-4.9.1 full recording, including testing the use of the graphic tutorial

Source: Internet
Author: User


Preface

GCC (GNU Compiler Collection, GNU Compiler Collection) is an open-source project on Linux and other UNIX-like platforms, software development and other essential tool chains (other members of the tool chain include binutils, glibc, libstdc ++, etc)

In addition, programmers and System Administrators often need to manually compile and install the software source code, whether it is a configure script or make tool/MAKEFILE file, in the end, GCC (or other compilers) needs to be called for actual compilation. Therefore, it is often necessary to use the new version of GCC and coexist with the old version of GCC to call it based on actual needs.


In this blog, we download the latest GCC source code package from the Internet based on the old GCC binary executable files installed on the centos 32-bit System and the glibc C library, perform simple tests, integrate with the make tool, PASS Parameters from the configure script, and optimize compilation.

The whole process is simple and clear, hoping to play a role in inspiring the enthusiasm of many enthusiasts for programming and learning.



Basic knowledge/prerequisites


Software Package terminology centos6.5 whether or not to install by default requires installation to compile and install GCC from the source code


GlibcThe C standard library implemented by the GNU project.

Source code package and binary RPM package, centos6.5 "minimal desktop" installation solution, installed by default in the form of RPM package,

Glibc is essential for compiling and installing GCC from source code in a non-Cross-compiling environment.

* ***** If it is a cross-compiling environment, that is, compiling on a hardware architecture/operating system (host machine ), however, the generated binary executable file must be run on another hardware architecture/operating system (target machine). In this case, the compiled C library on the host machine cannot be used, it is best to download the glibc source code and compile it on your own. *****



Glibc-staticThe static version of the gnu c standard library is only required for-static links,

There is only a binary RPM package in the yum software warehouse. centos6.5 "minimal desktop" installation solution is not installed by default,

Glibc-static is essential for compiling and installing GCC from source code in a non-Cross-compiling environment, and it depends on glibc (glibc must be installed first)


Libstdc ++C ++ standard library compatible with GCC.

There is only a binary RPM package in the yum software warehouse. centos6.5 "minimal desktop" installation solution is installed by default in the form of an RPM package,

When compiling and installing GCC from the source code, if you need to compile its components: C ++ Compiler (G ++), you need to rely on libstdc ++. Fortunately, the system has been installed.


GCC (old version installed)GNU Compiler Collection, including C, C ++ compilers, Fortran, Ada, and other compilers,

Source code package and binary RPM package. The yum software warehouse only has binary RPM packages and is an old version (version 4.4.7 ),

Centos6.5 "minimal desktop" installation solution, which is not installed in the old version by default,

Before you compile and install the new version of GCC from the source code, you must have installed the old version of GCC on the system.



Gcc-C ++The GNU Compiler's c ++ enhanced support package provides more support for the current C ++ standard specification to the gcc c ++ compiler, including template and error handling.

There is only a binary RPM package in the yum software warehouse. centos6.5 "minimal desktop" installation solution is not installed by default,

After the author's test, if gcc-C ++ is not installed in advance on the system, the make phase after the new GCC version is compiled will exit due to errors, gcc-C ++ may also require additional libstdc ++ support,

Therefore, it is best to install gcc-C ++ through Yum first.


To sum up, under the premise of centos6.5 "minimal desktop" installation solution, we need to install the following software packages:

GCC, GCC-C ++, glibc-static


Preparations


First, verify the status of the three software packages separately to ensure that:

[[Email protected] desktop] # rpm-Qi GCC [[email protected] desktop] # locate GCC [[[email protected] desktop] # Which GCC [[email protected] desktop] # whereis gcc
[[Email protected] desktop] # rpm-Qi gcc-C ++ [[email protected] desktop] # locate gcc-C ++ [[email protected] desktop] # Which gcc -C ++ [[email protected] desktop] # whereis gcc-C ++
[[Email protected] desktop] # rpm-Qi glibc-static [[email protected] desktop] # locate glibc-static [[email protected] desktop] # Which glibc-static [[ email protected] desktop] # whereis glibc-static



650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/42/2F/wKiom1PXDkzy5MXXAAnSPomFtSo998.jpg "Title =" screenshot.jpg "alt =" wkiom1pxdkzy5mxxaanspomftso998.jpg "/>



Next, let's take a look at the details about the two installed software packages: Glibc and libstdc ++:

[[Email protected] desktop] # rpm-Qi glibc [[email protected] desktop] # locate glibc [[email protected] desktop] # Which glibc [[email protected] desktop] # whereis glibc


[[Email protected] desktop] # rpm-Qi libstdc ++ [[email protected] desktop] # locate libstdc ++ [[email protected] desktop] # Which libstdc ++ [[ email protected] desktop] # whereis libstdc ++


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/42/30/wKioL1PXEsHBZO8dAAYBOkkdiVQ318.jpg "Title =" screenshot.jpg "alt =" wkiol1pxeshbzo8daaybokdivq318.jpg "/>



650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/42/30/wKiom1PXFGnhs0qKAAqlDcCRYnA800.jpg "Title =" screenshot.jpg "alt =" wkiom1pxfgnhs0qkaaqldccryna800.jpg "/>



With the basic knowledge above, you can use Yum to download and install the old GCC and glibc-static, GCC-C ++ RPM packages in binary format:

(By the way, the glibc version on yum is newer and can be used to upgrade the existing glibc of the system)



[[Email protected] desktop] # Yum check-update [[email protected] desktop] # Yum list GCC gcc-C ++ glibc-static glibc [[email protected] desktop] # yum install glibc-static GCC gcc-C ++

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/42/32/wKiom1PXHO3ifybJAAbEqZ7KIt4439.jpg "Title =" screenshot.jpg "alt =" wkiom1pxho3ifybjaabeqz7kit4439.jpg "/>


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/42/35/wKioL1PXJWjST1nyAAzvVOGqtsA782.jpg "Title =" screenshot.jpg "alt =" wkiol1px1_jst1nyaazvvogqtsa782.jpg "/>


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/42/37/wKiom1PXKI_B0rUyAAuSVd7U3dk449.jpg "Title =" screenshot.jpg "alt =" wkiom1pxki_b0ruyaausvd7u3dk449.jpg "/>


Let's first query the paths of the installed old GCC and G ++ files. These paths will be used in later stages: (used to implement coexistence of the New and Old GCC versions on the system, (Optional)


[[Email protected] desktop] # Which GCC [[email protected] desktop] # which G ++ [[email protected] desktop] # whereis GCC [[email protected] desktop] # whereis g ++ [[email protected] desktop] # rpm-QL glibc-static


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/42/3F/wKioL1PXMTKTZegTAAcwXuCP6l8102.jpg "Title =" screenshot.jpg "alt =" wkiol1pxmtktzegtaacwxucp6l8102.jpg "/>


From the above output, we know that:

After the first installation (earlier version) of GCC, install it in/usr/bin/GCC/usr/lib/GCC/usr/libexec/GCC/usr/share/man/Man1/gcc.1.gz,

It can be seen that the system defaults the GCC

Executable File (installed to/usr/bin/GCC ),

Library file (installed to/usr/lib/GCC ),

Compiler (PC3)/pre-linker (collect2) (installed to/usr/libexec/GCC)

Put it in different directories,
(The header file is in the/usr/lib/GCC/i686-redhat-linux/4.4.4/include directory)


Among them, cc0 is responsible for compiling the source file; collect2 is pre-linked, and the actual link is completed by the linker LD;
In centos6.5, the minimal desktop installation installs the executable files of the assembler as in/usr/bin/as by default, and the executable files of the linker LD are installed in/usr/bin/LD by default;


In addition, executable files in the/bin and/sbin directories are generally called by users by entering commands in shell; executable files in the/usr/libexec/directory, generally, it is not directly called by users, but by a program or tool software to help the former complete a specific task.


Since gcc4.4.7, it is recommended that you use a separate directory instead of compiling it in the directory After decompressing the GCC source code because:

Optimize and generate binary executable files with better performance;

Avoid unexpected errors;

Avoid contamination to the directory where the source code is located;


Therefore, we need to create three directories under the root directory/of the file system to facilitate the management of the compilation process;

You also need/Usr/local/Directory to store the latest version of GCC, and use

Configure script-- Prefix =/usr/local/[custom path name]In this way, the GCC executable files, library files, and header files will be stored in the corresponding subdirectories in an orderly manner, and will be directly unavailable in the future.Rm-RFThe entire installation path is fine, because GCC does not have the uninstall function to uninstall.


Compared with the earlier version of GCC, the/usr/bin,/usr/lib/usr/libexec directory is used to store their respective files. This centralized management method is more efficient and secure, unmount or delete unrelated files without errors.


The above nonsense is expressed using shell commands as follows:


[[Email protected] desktop] # cd/[[email protected]/] # mkdir {downloaded-Src-Dir, extracted-Src-Dir, compile-Dir} [[email protected]/] # cd/usr/local [[email protected] local] # mkdir new-exec-gcc-4.9.1 [[email protected] local] # cd new-exec-gcc-4.9.1 /[[ email protected] new-exec-gcc-4.9.1] # PWD/usr/local/new-exec-gcc-4.9.1


After all the preparations are completed, we will download the site from the official FTP of the GNU gcc project:


Ftp://gcc.gnu.org/pub/gcc/releases/


To download the latest GCC source code package. For authoritative information and version update instructions, you can obtain the installation guide here:

Https://gcc.gnu.org/








































This article is from the "4681835" blog, please be sure to keep this source http://4691835.blog.51cto.com/4681835/1531682

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.