Installation Steps for LINUX-GCC

Source: Internet
Author: User

Follow the steps and setup options provided in this article to install GCC on the system even if GCC has not been installed before.
A new working version of the GCC compiler.

1. Download

Find the download resources on the GCC website (http://gcc.gnu.org/) or by searching online. Current GC
The latest version of C is 3.4.0. Two types of files are available for download: gcc-3.4.0.tar.gzand gcc-3.4.0.tar.bz2,
The compression format is different, and the content is completely consistent. Download one of them.

2. Extract

Based on the compression format, select one of the following methods to unpack (the following "%" indicates 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, represented by $ {srcdir. In the future, $ {srcdir
}, Replace it with a real path. Run the PWD command to view the current path.

Detailed gccinstallation instructions are provided in the $ {srcdir}/installobject directory. You can open index.html with a browser.

3. Create the target directory

The target directory (represented by $ {objdir}) is used to store the compilation result. GCC recommends that the compiled files not be
Put it in the source directory $ {srcdir] (although this can also be done), it is best to store it in another directory separately, and do not
It can be a subdirectory of $ {srcdir.

For example, you can create a GCC-build
Target directory (the same as the source directory $ {srcdir ):

% Mkdir gcc-build
% Cd gcc-build

The following operations are mainly performed in the target directory $ {objdir.

4. Configuration

The purpose of the configuration is to determine where the GCC compiler is installed ($ {destdir}), languages supported, and
Set other options. $ {Destdir} cannot be the same as the $ {objdir} or $ {srcdir} directory.

The configuration is completed by running configure under $ {srcdir. The command format is (remember to use your real path
Path replacement $ {destdir }):

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

For example, if you want
3.4.0 install to the/usr/local/gcc-3.4.0 directory, then $ {destdir} indicates this path.

On my machine, I configured it as follows:

% ../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 ages = C, C ++, Java

Install GCC in the/usr/local/gcc-3.4.0 directory and support the C/C ++ and Java languages. For other options, see gcc
Help description.

5. Compile

% Make

This is a long process. On my machine (P4-1.6), it took over 50 minutes.

6. Install

Run the following command to copy the compiled library files to the $ {destdir} directory (according to the path you set, you can
Administrator permissions are required ):

% Make install

Now, the GCC 3.4.0 installation process is complete.

6. other settings

Gcc
All 3.4.0 files, including command files (such as GCC and G ++) and library files, are saved in the $ {destdir} directory.
Put, such as placing command files in the bin directory, library files under Lib, and header files under include. Because of the command file and
The directory where the library file is located is not included in the corresponding search path. Therefore, you must make appropriate settings before the Compiler
They can be found and used smoothly.

6.1 GCC, G ++, and gcj settings

To use gcc
3.4.0 GCC and other commands, the simple method is to put its path $ {destdir}/bin in the environment variable path. I am not
In this way, it is implemented through symbolic connections. The advantage of doing so is that I can still use the old
Version of the GCC compiler.

First, check the path of the original GCC:

% 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
In 3.4.0, commands such as GCC, G ++, and gcj are respectively connected by a symbol in the/usr/bin directory:

% Cd/usr/bin
% Ln-S $ {destdir}/bin/GCC gcc34
% Ln-S $ {destdir}/bin/g ++ 34
% Ln-S $ {destdir}/bin/gcj gcj34

In this way, gcc34, G ++ 34, and gcj34 can be used to call GCC respectively.
3.4.0 GCC, G ++, and gcj have compiled C, C ++, and Java programs. At the same time, the old version of GC can still be used
C compiler GCC, G ++ and other commands.

6.2 database path settings

Add the $ {destdir}/lib path to the environment variable LD_LIBRARY_PATH. It is best to add it to the system configuration file.
So that you do not need to set this environment variable every time.

For example, if GCC 3.4.0 is installed in the/usr/local/gcc-3.4.0 directory
In Linux, you can directly execute the command line 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

Use the new compilation commands (gcc34, G ++ 34, and so on) to compile your previous C and C ++ programs and verify the newly installed GCC compilation.
Whether the device works properly.

8. You can delete or retain the $ {srcdir} and $ {objdir} directories as needed.

Postscript:

GCC just installed two days ago
3.4.0. This article is formed by recording the Installation planning, installation process, and precautions. We hope that,
In particular, if you have not installed GCC, it will be helpful when installing 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.