o(╥﹏╥)oSad

WeChat cannot downloadGNU Compiler Collection (gcc compiler), but just click on the upper right corner and select open in browser or Safari!
GNU Compiler Collection (gcc compiler)

GNU Compiler Collection (gcc compiler)

The GNU Compiler Collection is a set of free software released under GPL and LGPL licenses. It is also a key part of the GNU project and a standard compiler for free Unix-like and Apple computer Mac OS X operating systems.
GCC (especially the C language compiler) is often considered the de facto standard for cross-platform compilers.
GCC was originally called GNU C Compiler (GNU C Compiler) because it could only process C language.
GCC was quickly extended to handle C++. Later it became available to handle Fortran, Pascal, Objective-C, Java, as well as Ada and other languages.

GNU Compiler Collection (gcc compiler)

【How to use】

Unzip

Copy gcc-4.1.2.tar.bz2 (the compressed file I downloaded) to /usr/local/src (choose according to your preference). According to the compression format, choose the corresponding method below to unpack (the following "% ” means command line prompt):

% tar zxvf gcc-4.1.2.tar.gz
or
% bzcat gcc-4.1.2.tar.bz2 | tar xvf -

The newly generated gcc-4.1.2 directory is called the source directory, and ${srcdir} is used to represent it. In the future, wherever ${srcdir} appears, it should be replaced with the real path. Use the pwd command to view the current path.

There are detailed GCC installation instructions in the ${srcdir}/INSTALL directory. You can open index.html with a browser to read.

Create target directory
The target directory (represented by ${objdir}) is where the compilation results are stored. GCC recommends that compiled files should not be placed in the source directory ${srcdir] (although this is also possible). It is best to store them in another directory separately, and not in a subdirectory of ${srcdir}.

For example, you can create a target directory called /usr/local/gcc-4.1.2 like this:

% mkdir /usr/local/gcc-4.1.2
% cd gcc-4.1.2

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

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

Configuration is completed by executing configure under ${srcdir}. The 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 4.1.2 to the /usr/local/gcc-4.1.2 directory, ${destdir} represents this path.

On my machine, I configured it like this:

% ../gcc-4.1.2/configure --prefix=/usr/local/gcc-4.1.2 --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-4.1.2 directory. It supports C/C++ and JAVA languages. For other options, see the help provided by GCC.

compile

% make

Install

Execute the following command to copy the compiled library files to the ${destdir} directory (administrator permissions may be required depending on the path you set):

% make install

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

Other settings

All files of GCC 4.1.2, including command files (such as gcc, g++), library files, etc., are stored separately in the ${destdir} directory. For example, command files are placed in the bin directory, library files are under lib, and header files are under include inferior. Since the directories where the command files and library files are located are not included in the corresponding search paths, appropriate settings must be made before the compiler can successfully find and use them.

Settings for gcc, g++, gcj

To use GCC 4.1.2's gcc and other commands, the simple way is to put its path ${destdir}/bin in the environment variable PATH. I don't use this method, but use symbolic links to implement it. The advantage of this 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 located:

% 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 a symbolic link for the gcc, g++, gcj and other commands in GCC 4.1.2 in the /usr/bin directory:

% cd /usr/bin
% ln -s ${destdir}/bin/gcc gcc412
% ln -s ${destdir}/bin/g++ g++412
% ln -s ${destdir}/bin/gcj gcj412

In this way, you can use gcc412, g++412, and gcj412 respectively to call gcc, g++, and gcj of GCC 4.1.2 to complete the compilation of C, C++, and JAVA programs. At the same time, you can still use the gcc, g++ and other commands in the old version of the GCC compiler.

Library path settings

Add the ${destdir}/lib path to the environment variable LD_LIBrarY_PATH. For example, if GCC 4.1.2 is installed in the /usr/local/gcc-4.1.2 directory, it can be executed directly on the command line under RH Linux
% export LD_LIBRARY_PATH=/usr/local/gcc-4.1.2/lib

It is best to add it to the system configuration file, so that you do not need to set this environment variable every time. Add the following two sentences to the file $HOME/.bash_profile:
LD_LIBRARY_PATH=/usr/local/gcc-4.1.2/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

Restart the system and the settings will take effect, or execute the command
% source $HOME/.bash_profile

test
Use new compilation commands (gcc412, g++412, etc.) to compile your previous C and C++ programs and check whether the newly installed GCC compiler can work properly

Version: 4.7.0 linux version | Update time: 2024-11-01

Similar recommendations

Latest updates

GNU Compiler Collection (gcc compiler) comments

  • 1st floor Huajun netizen 2018-03-21 03:45:25
    GNU Compiler Collection (gcc compiler) is not bad, the download is very fast, I give you a good review!
  • 2nd floor Huajun netizen 2021-05-05 17:55:30
    GNU Compiler Collection (gcc compiler) hopes to get better and better, come on!
  • 3rd floor Huajun netizen 2019-06-25 15:23:44
    GNU Compiler Collection (gcc compiler) is convenient, practical and powerful. The software is very easy to use!

Recommended products

Everyonealso likeThese:

+

This application has not passed real-name authentication. You can download it through the mobile assistant.

CancelOK