Information Source: chinaunix Author: whyglinux
The latest version of the GCC compiler is released. Currently, GCC can be used to compile languages such as C / C , Fortran, Java, Objc, ADA, and select the installation supported language as needed. GCC 3.4.0 better supports C standards than previous versions. This article describes GCC3.4.0 on redhat Linux as an example, and introduces the GCC installation process.
Before installation, there must be a CC or GCC and other compiler, and is available, or the compiler on the system is specified with an environment variable CC. If there is no compiler on the system, GCC 3.4.0 in the source code form cannot be installed. If this is the case, you can find a GCC software package that is compatible with your system, such as RPM, such as RPM. This article describes the installation process of the GCC package provided in the form of source code, the package itself and its installation process are also applicable to other Linux and UNIX systems.
The original GCC compiler on the system may be in different directories such as command files such as GCC, library file, header file, and the like, respectively. Unlike this, GCC now recommends that we install a version of GCC in a separate directory. The advantage of this is that it is easy to delete the entire directory when it is not required in the future (because the GCC does not have a uninstall function); the disadvantage is that some settings will be done normally after the installation is complete. In this article I use this scenario to install GCC 3.4.0, and after the installation is complete, it is still possible to use the original low version of the GCC compiler, ie, on a system, can exist and use multiple versions of the GCC compiler.
According to the steps and setting options provided herein, even if the GCC is not installed, you can install a work-on-version GCC compiler.
Download
You can find download resources on the GCC website (http://gcc.gnu.org/) or by online search. At present, the latest version of GCC is 3.4.0. Files available for download generally have two forms: GCC-3.4.0.tar.gz and GCC-3.4.0.tar.bz2, just the compressed format, the content is exactly the same, download one of them.
2. Unzip
According to the compressed format, select the following way to unpack (the following "%" means that the 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 is called a source directory, indicating it with $ {srcdir}. In the future, there are places where $ {srcdir}, you should replace it with a real path. Use the PWD command to view the current path.
There is a detailed GCC installation instructions in the $ {srcdir} / install directory, and you can use the browser to open index.html reading.
3. Establish a target directory
The target directory (represented with $ {ObjDir}) is where the compile results are stored. GCC recommends compiled files Do not place in source directory $ {srcdir] (although doing this), it is best to store in another directory, and cannot be a subdirectory of $ {srcdir}.
For example, you can create a target directory called GCC-Build (with source directory $ {srcdir}):
% MKDIR GCC-Build
% CD GCC-Build
The following operations are mainly conducted under the target directory $ {ObjDir}.
4. Configuration
The purpose of the configuration is to determine where the GCC compiler is installed ($ {destdir}), support what language and specify some other options. Where $ {destdir} cannot be the same as $ {ObjDir} or $ {srcdir} directory.
The configuration is done by executing Configure under $ {srcdir}. Its command format is (remember to replace $ {destDir}):% $ {srcdir} / configure --prefix = $ {destdir} [other options]
For example, if you want to install GCC 3.4.0 to the /usr/local/gcc-3.4.0 directory, $ {destdir} represents this path.
On my machine, I am configured like this:
% ../gcc-3.4.0/configure --prefix = / usr / local / gcc-3.4.0 --enable-trreads = POSIX - DISABLE-CHECKING --ENABLE - Long-long --host = i386 -redhat-linux --with-system-zlib --enable-languages = C, C , Java
Install GCC in /usr/local/gcc-3.4.0 directory, support C / C and Java languages, and other options see the help description provided by GCC.
5. Compilation
% make
This is a long process. On my machine (P4-1.6), this process has been used for more than 50 minutes.
6. Installation
Execute the following command to copy the compiled library files to the $ {destdir} directory (according to your set path, you may need administrator's permissions):
% make install
At this point, the GCC 3.4.0 installation process is completed.
6. Other settings
All files of GCC 3.4.0 include command files (such as GCC, G ), library files, etc., are stored separately in $ {destdir} directory, such as command files in bin directory, library files under lib, header files Include, wait. Since the directory where command files and library files are not included in the corresponding search path, the compiler must be successfully found and used smoothly.
6.1 GCC, G , GCJ setting
To use GCC 3.4.0 GCC, a simple method is to put its path $ {destDir} / bin in the environment variable Path. I don't have to use this way, but use symbolic connections to connect, so the benefit is that I can still use the original old version of the GCC compiler on the system.
First, check the path where the original GCC is:
% Which GCC
On my system, the above command displays: / usr / bin / gcc. Therefore, the original GCC command is in / usr / bin directory. We can make a symbolic connection to GCC, G , GCJ in GCC 3.4.0, etc. in / usr / bin directory:
% 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, GCC34, G 34, GCJ34 can be used to call GCC, G , and GCJ completed compilation of C, C , and Java programs, respectively, using GCC 3.4.0. At the same time, it is still able to use the GCC, G or other commands in the old version of the GCC compiler.
6.2 Settings of the library path
Add a $ {destdir} / lib path to the environment variable ld_library_path, it is best to add to the system's configuration file, so you don't have to set this environment variable each time.
For example, if GCC 3.4.0 is installed in /usr/local/gcc-3.4.0 directory, you can execute them directly on the command line under RH Linux or add the following: STENV LD_Library_Path / USR / Local / GCC-3.4.0 / LIB: $ ld_library_path
7. Test
Compile your previous C, C programs with new compile commands (GCC34, G 34, etc.) to verify that the newly installed GCC compiler can work properly.
8. Delete or retained $ {srcdir} and $ {ObjDir} directories as needed.
Reference:
Installing GCC (http://gcc.gnu.org/install/)
postscript:
The GCC 3.4.0 was installed in the first two days, and the installation plan, installation process, and some precautions were recorded in this article. I hope to help everyone, especially friends who have not installed GCC, are helping when installing GCC.