Installing the GCC compiler process on Linux

Source: Internet
Author: User
Tags bz2 versions linux

April 20, 2004 the latest version of the GCC compiler 3.4.0 released. At the moment, GCC can be used to compile programs in C + +, FORTRAN, JAVA, OBJC, and Ada languages, and you can choose to install supported languages as needed. GCC 3.4.0 supports the C + + standard better than previous versions. This article introduces the installation process of GCC with the installation of GCC3.4.0 on Redhat Linux as an example.

Prior to installation, the system must have a compiler such as CC or GCC, available, or use the environment variable CC to specify the compiler on the system. If there is no compiler on the system, you cannot install the GCC 3.4.0 in the form of source code. If this is the case, you can find a network with your system, such as RPM, such as binary form of the GCC package to install the use. This article describes the installation process for the GCC packages provided in source code, and the software packages themselves and their installation processes apply to other Linux and UNIX systems as well.

The original GCC compiler on the system may be put GCC, such as command files, library files, headers, etc., respectively, to the system in different directories. Unlike this, GCC now recommends that we install a version of GCC in a separate directory. The advantage of this is that you can easily delete the entire directory when you don't need it in the future (because GCC does not have the uninstall feature); The disadvantage is that you have to do some setup work to make the compiler work properly after the installation is complete. I installed the GCC 3.4.0 in this article, and after the installation was complete, I was able to use the original low version of the GCC compiler, a system that can exist simultaneously and use multiple versions of the GCC compiler.

Follow the steps and setup options provided in this article to install a new, working version of the GCC compiler on your system, even if you have not previously installed GCC.

1. Download

Download resources can be found on the GCC website (http://gcc.gnu.org/) or through an online search. The latest version of GCC is currently 3.4.0. There are two types of files available for downloading: gcc-3.4.0.tar.gz and gcc-3.4.0.tar.bz2, but the compression format is not the same, the content is exactly the same, download one of them.

2. Decompression

Depending on the compression format, select the appropriate way to unpack (the following "%" represents a command-line prompt):

% tar xzvf gcc-3.4.0.tar.gz

Or

% Bzcat gcc-3.4.0.tar.bz2 | Tar xvf-

The newly generated gcc-3.4.0 directory is called the source directory and is represented by ${srcdir}. In the future, where ${srcdir} appears, you should replace it with a real path. Use the PWD command to view the current path.

Detailed GCC installation instructions are available in the ${srcdir}/install directory, and index.html reading can be opened in the browser.

3. Establish the target directory

The target directory (represented by ${objdir}) is where the results of the compilation are to be stored. GCC recommends that compiled files not be placed in the source directory ${srcdir] (although this can be done), preferably separately in another directory, and cannot be a subdirectory of ${srcdir}.

For example, you can create a target directory called Gcc-build (with the source directory ${srcdir} is a sibling directory):

% mkdir Gcc-build

% CD Gcc-build

The following operations are performed primarily under the target directory, ${objdir}.

4. Configure

The purpose of the configuration is to decide where to install the GCC compiler (${destdir}), what languages to support, and other options to specify. Where ${destdir} cannot be the same as the ${objdir} or ${srcdir} directory.

The configuration is done by executing the Configure under ${srcdir}. Its command format is (remember to replace ${destdir} with your real path):

% ${srcdir}/configure--prefix=${destdir} [other options]

For example, if you want to install GCC 3.4.0 into the/usr/local/gcc-3.4.0 directory, ${destdir} represents the path.

On my machine, I was configured like this:

% .. /gcc-3.4.0/configure--prefix=/usr/local/gcc-3.4.0--enable-threads=posix--disable-checking--enable--long-long-- Host=i386-redhat-linux--with-system-zlib--enable-languages=c,c++,java

Install GCC in the/usr/local/gcc-3.4.0 directory, support the C + + and Java languages, and other options see the help provided by GCC.

5. Compile

% make

This is a long process. On my Machine (p4-1.6), the process took more than 50 minutes.

6. Installation

Execute the following command to copy the compiled library files to the ${destdir} directory (depending on the path you set, you may need Administrator privileges):

% make Install

At this point, the GCC 3.4.0 installation process is complete.

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.