Compile and install GCC on Linux

Source: Internet
Author: User
Compile and install GCC on Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: A. TNG
Email: jiyucn@163.com
Reference: Installation document of GCC
Time: 4/13/2008

Preface
Recently, a development environment has been built, which has special requirements on GCC. The GCC installed using the RPM package can no longer meet the requirements. Therefore, it is decided to manually compile and install GCC.

I originally wanted to take some shortcuts and hoped that the RPM package installation could also achieve the flexibility of manual installation. Later I found that this path was not available. Next I wanted to find out whether the compiled tar package is available for downloading on the network, after decompression, you can run it directly. Later, it was found that the GCC platform was highly dependent and the path was also unavailable.

Therefore, you can only select the source code to compile and install GCC.

Step 1: Prepare
I started to install GCC from a Linux PC with minimal CentOS 5 installation. In fact, if you have a Linux PC with a development environment installed, skip this step.

First, GCC must be installed on the machine to compile and install the new GCC from the source code. Therefore, I have installed the following RPM packages as the development environment. (Note that my system is CentOS 5, and you can select related Development Kits for other platforms ).

Rpm-ivh cpp-4.1.1-52.el5.i386.rpm
Rpm-ivh glibc-headers-2.5-12.i386.rpm
Rpm-ivh glibc-devel-2.5-12.i386.rpm
Rpm-ivh libgomp-4.1.1-52.el5.i386.rpm
Rpm-ivh gcc-4.1.1-52.el5.i386.rpm
Rpm-ivh libstdc ++ devel-4.1.1-52.el5.i386.rpm
Rpm-ivh gcc-c ++-4.1.1-52. el5.i386. rpm
Rpm-ivh zlib-devel-1.2.3-3.i386.rpm

After the above toolkit is installed, the gcc/g ++ command is available in the system.

The GCC tar package provides test suite, which can be executed after compilation to analyze whether the compilation is successful. Therefore, another toolkit must be installed in the system:

Rpm-ivh expect-5.43.0-5.1.i386.rpm
Rpm-ivh dejagnu-1.4.4-5.1.noarch.rpm

After the above toolkit is installed, the runtest command in the system can be used.

Step 2: configure and make
Configure
Configure is a key step. If a compilation error occurs, you should first think of the configure problem, and then think of the lack of software packages in the system, header files cannot be found during compilation.

The compilation parameters I use are:
. /Configure -- prefix =/opt/gcc-x.y.z -- enable-shared \ -- enable-threads = posix -- enable-clocale = gnu \ -- enable-_ cxa_atexit -- disable-checking \ -- enable -- long-long

Explanation:
-- Prefix =/opt/gcc-x.y.z is used to specify the installation directory, note that the directory should not be the same as the source code, it cannot be the source code subdirectory.
-- Enable-shared Library Creation
-- Enable-threads = posix enables thread support, which is the default value on some platforms. It affects the Obj-C library and the exception handling of C ++ and Java.
-- Enable-clocale = gnu this parameter ensures that the C ++ library uses the correct locale module in all circumstances. If the configuration script finds the locale de_DE, it uses the correct gnu module. However, if de_DE is not installed, it is possible to create a C ++ library file that is not compatible with ABI. This is because generic is used as the locale module by mistake.
-- Enable-_ cxa_atexit uses _ cxa_atexit instead of atexit to record local and global C ++ destructors, in order to fully comply with the standards. It also affects C ++ ABI, so the generated C ++ shared library can also be used on other Linux releases.
-- Disable-checking: to save Compilation Time, we use this option without affecting the result.
-- Enable -- long-long supports the long data type, which is used by some open-source projects.
After configure is completed, Makefile is automatically generated, and then you can start a long compilation process.

If the configure parameter bypasses you very much and passes as few parameters as possible to configure, the default parameter is applicable in most cases.

Make

Run the following command to start Compilation:
Make bootstrap
For machines with different configurations, the compilation duration is different. The same process is extremely long.

Step 3: perform the test (optional)
The GCC tar package provides test suite to help you test the compilation.

Run the following command to start the test:
Make-k check> check. log
Similarly, this is a long process.

After the test is complete, you can access the http://gcc.gnu.org/buildstat.html to compare the test results.

Step 4: Install
If there are no errors, you can start the installation:

Make install
Related Article

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.