Installing the GCC compiler process on Linux _unix Linux

Source: Internet
Author: User
Tags bz2

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.

6. Other Settings

All files in gcc 3.4.0, including command files (such as GCC, g++), library files, etc. are stored in the ${destdir} directory, such as the command file is placed in the bin directory, the library file is under LIB, the header file is under include and inferior. Because the directory where the command files and library files are located is not yet included in the appropriate search path, the compiler must make the appropriate settings to find and use them successfully.

6.1 gcc, g++, GCJ settings

A simple way to use GCC 3.4.0, such as GCC, is to place its path ${destdir}/bin in the environment variable path. I do not use this method, but the symbolic connection, the advantage of this is that I can still use the original version of the GCC compiler on the system.

First, look at the path where the original GCC resides:

% which GCC

On my system, the above command shows:/USR/BIN/GCC. Therefore, the original GCC command is in the/usr/bin directory. We can make the GCC, g++, gcj in the GCC 3.4.0 in the/usr/bin directory, respectively, a symbolic connection:

% Cd/usr/bin
% ln-s ${DESTDIR}/BIN/GCC gcc34
% ln-s ${destdir}/bin/g++ g++34
% ln-s ${DESTDIR}/BIN/GCJ gcj34

In this way, you can use Gcc34, g++34, gcj34 to invoke GCC 3.4.0 gcc, g++, gcj to complete the C, C + +, Java program compiled. Also, you can still use the GCC, g++, and other commands in the old version of the GCC compiler.

6.2 Library Path settings

Adding the ${destdir}/lib path to the environment variable Ld_library_path is best added to the system's configuration file so that you do not have to set the environment variable every time.

For example, if the GCC 3.4.0 is installed in the/usr/local/gcc-3.4.0 directory, it can be executed directly on the command line under RH Linux or add the following sentence to the file/etc/profile:

Setenv ld_library_path/usr/local/gcc-3.4.0/lib: $LD _library_path

7. Test

Compile your previous C and C + + programs with the new compiler command (GCC34, g++34, etc.) to verify that the newly installed GCC compiler is working correctly.

8. ${srcdir} and ${objdir} directories can be deleted or retained as required.

Postscript:

The first two days just installed GCC 3.4.0, the installation planning, installation process, some notes on the formation of this article. Hopefully it will be helpful for everyone, especially those who have not installed GCC, to install GCC.


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.