Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install gcc under linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to install gcc under linux, which is very detailed and has certain reference value. Friends who are interested must finish reading it!

1. Get to know gcc

At present, GCC can be used to compile programs in languages such as CAccord +, FORTRAN, JAVA, OBJC, ADA, etc., and you can choose which languages to install according to your needs. My own linux is version 4.1.2, which does not support openMP, and I want to use openMP, so I installed a version 4.2 or above on the original basis.

Before installation, the system must have a compiler for cc or gcc. If not, you cannot install a higher version of gcc. If this is the case, you can find a binary GCC package suitable for your system, such as RPM, to install and use.

This article describes the process of installing gcc with source code. I installed it in a separate directory. If you want to uninstall it later, just delete the directory. This article describes the detailed process of installing version 4.3.4. Just follow these steps to install it step by step.

2. Installation package that needs to be downloaded

2.1 download gcc

The download URL is http://ftp.gnu.org/gnu/gcc/, which version you can download according to your needs. I chose version 4.3.4. There are gcc-4.3.4.tar.bz2,gcc-4.3.4.tar.gz in it. Just choose one of them. They are exactly the same. I chose gcc-4.3.4.tar.gz. You can also check Changes: http://gcc.gnu.org/gcc-4.5/changes.htm. If there are any changes compared to the previous version, you can just take a look at them.

2.2 download 3 dependency packages

One is mpc, one is gmp, the other is mpfr, and the download address is: ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz, ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2, http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.2.tar.gz. The order of installation is: GMP,mpfr, mpc, and finally install gcc. I started by installing gcc directly, and the following message appeared during the configuration process:

Configure: error: Building GCC requires GMP 4.2, MPFR 2.3.1 + and MPC 0.8.0+.Try the-- with-gmp,-- with-mpfr and/or-- with-mpc options to specify their locations.

Before installing gcc, you must install GMP 4.2 or above, MPFR2.3.1 or above, and MPC 0.8.0 or above.

3. Installation steps

Install GMP-5.0.1.

I chose the GMP5.0.1 version here. After extracting the gmp-5.0.1, I get the source code directory and create a temporary compilation directory, temp.

$tar-jxvf gmp-5.0.1.tar.bz2 $cd gmp-5.0.1$ mkdir temp$ cd temp

Start configuring the installation directory, and after entering the temp directory, enter the following command:

$.. / configure-- prefix=/usr/local/gmp-5.0.1$ make$ make install

This completes the installation of gmp. The process of installing mpfr and mpc is similar, except that dependencies have to be added during installation.

3.2 install mpfr

I chose version 3.1.2 of mpfr here. Extract, set up a temporary compilation directory temp, and enter the temp directory

$tar-zxvf mpfr-3.1.2.tar.gz $cd mpfr-3.1.2$ mkdir temp$ cd temp$.. / configure-- prefix=/usr/local/mpfr-3.1.0-- with-gmp=/usr/local/gmp-5.0.1$ make$ make install

Where-- with=/usr/local/gmp-5.0.1 is the dependency and / usr/local/gmp-5.0.1 is the directory where gmp is installed

3. 3 install mpc

I chose version 1.0.2 of mpc. Extract, set up a temporary compilation directory temp, and enter the temp directory.

$tar-zxvf mpc-1.0.2.tar.gz$ cd mpc-1.0.2$ mkdir temp$ cd temp$.. / configure-- prefix=/usr/local/mpc-1.0.2-- with-gmp=/usr/local/gmp-5.0.1-- with-mpfr=/usr/local/mpfr-3.1.0$ make$ make install

Remember the last two dependencies, that is, the installation directory of your gmp and mpfr

3.4 install gcc

The three previous installations are all in preparation for the installation of gcc. Extract the installation package for gcc

$tar zxvf gcc-4.3.4.tar.gz or $tar jxvf gcc-4.5.1.tar.bz2

The resulting directory gcc-4.3.4 is the source directory, represented by ${srcdir}. There is a detailed installation process in the INSTALL directory in gcc-4.3.4, which is all in English, and the source directory is also indicated by ${srcdir}. I am unzipped in / usr/local/src/gcc-4.3.4 directory.

Establish a target directory

$mkdir / usr/local/gcc-4.3$ cd gcc-4.3

This is the target directory, that is, the compiled directory, and then all of the following operations are done in that directory. Use ${objdir}

Set up the installation directory

$mkdir / usr/local/gcc-4.3.4

This is where your gcc is installed. Denoted by ${destdir}. Start the configuration

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

Remember to replace ${srcdir} and ${destdir} with the real directory when installing. That's what mine says.

$/ usr/local/src/gcc-4.3.4/configure-prefix=/usr/local/gcc-4.3.4-enable-threads=posix-disable-checking-enable--long-long-enable-languages=c,c++,java-with-gmp=/usr/local/gmp-5.0.1-with-mpfr=/usr/local/mpfr-3.1.0-with-mpc=/usr/local/mpc-1.0.2

Remember to add the last three dependencies, or you will make the mistake you just made. Then install

$make$ make install

It takes a long time to install, about two hours.

3.5 gcc, Gmail +, gcj settings

The easy way to use commands such as gcc of GCC 4.3.4 is to put its path ${destdir} / bin in the environment variable PATH. Instead of doing this, I do it in symbolic concatenation, which has the advantage that I can still use the old version of the GCC compiler on the system.

The original path of gcc is under usr/bin. We can make a symbolic connection to the commands such as gcc, Gmail + and gcj in gcc 4.3.4 in the / usr/bin directory:

$cd / usr/bin$ ln-s / usr/local/gcc-4.3.4/bin/gcc gcc434 $ln-s / usr/local/gcc-4.3.4/bin/g++ galleys 434$ ln-s / usr/local/gcc-4.3.4/bin/gcj gcj434

In this way, the C, C++ and JAVA programs can be compiled by calling gcc, Gmail + and gcj of GCC 4.1.2 using gcc434, Group434 and gcj434, respectively. At the same time, you can still use commands such as gcc, Gmail +, and so on, from older versions of the GCC compiler.

3.6 setting of the library path

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

$export LD_LIBRARY_PATH=/usr/local/gcc-4.3.4/lib

It's best to add it to the system's configuration file so that you don't have to set this environment variable every time, add the following two sentences to the file $HOME/.bash_profile:

LD_LIBRARY_PATH=:/usr/local/mpc-1.0.2/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-3.1.2/lib:/usr/local/gcc-4.3.4/libexport LD_LIBRARY_PATH

Or add it under / etc/bash_profile.

Restart the system settings take effect, or execute the command

$source $HOME/.bash_profile

Or:

$source / etc/bash_profile

Compile your previous C, C++ programs with new compilation commands (gcc412, glossary 412, etc.) and verify that the newly installed GCC compiler works properly.

After Linux installs GCC, you can easily edit it.

The above is all the contents of how to install gcc in linux. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report