search

How to install gcc under linux?

1. Learn about gcc 

Currently, GCC can be used to compile programs in C/C, FORTRAN, JAVA, OBJC, ADA and other languages. You can choose to install supported languages ​​according to your needs. My own Linux is version 4.1.2, which does not support openMP, and I need to use openMP, so I installed a version 4.2 or above on the original basis.

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

This article introduces the process of installing gcc from source code. I installed it in a separate directory. If you want to uninstall it in the future, just delete the directory. This article introduces Detailed process for installing version 4.3.4. Just follow the steps below 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/. You can download which version according to your needs. I chose version 4.3.4. There are gcc-4.3.4.tar.bz2 and gcc-4.3.4.tar.gz in it. Just choose any one. They are exactly the same. I chose gcc-4.3.4.tar.gz. You can also view Changes: http://gcc.gnu.org/gcc-4.5/changes.htm. You can just take a look at the changes compared to the previous version.

2.2 Download 3 dependency packages

One is mpc, one is gmp, and one is mpfr. The download addresses are: 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 gcc. I installed gcc directly from the beginning, 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.

prompts that before installing gcc, GMP 4.2 or above, MPFR 2.3.1 or above, MPC 0.8.0 or above must be installed. Version.

3. Installation steps

##3.1 Install GMP-5.0.1.

What I chose here is the GMP5.0.1 version. After decompressing gmp-5.0.1, 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. After entering the temp directory, enter the following command:

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

In this way, the gmp installation is completed. The process of installing mpfr and mpc is similar, except that you have to add dependencies during installation

##3.2 Install mpfr

What I chose here is version 3.1.2 of mpfr. Unzip, create a temporary compilation directory temp, 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 a dependency, /usr/local/gmp-5.0.1 is the installation directory of gmp

3.3 Install mpc

I chose the 1.0.2 version of mpc. Unzip it, create 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 dependencies of the latter two items, which are the installation directories of your gmp and mpfr

##3.4 Install gcc

The three previously installed are all preparations for installing gcc. Unzip the gcc installation package

$ tar zxvf gcc-4.3.4.tar.gz 或者 $ tar jxvf gcc-4.5.1.tar.bz2

and the directory gcc-4.3.4 obtained is the source directory, represented by ${srcdir}. There are detailed installation procedures in the INSTALL directory in gcc-4.3.4. They are all in English, and the source directories inside are also represented by ${srcdir}. I unzipped it in the /usr/local/src/gcc-4.3.4 directory. Create the target directory

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

This is the target directory, which is the compiled directory, and all the following operations are performed in this directory. Use ${objdir}

Create the installation directory

$ mkdir /usr/local/gcc-4.3.4

This is where your gcc is installed. Represented by ${destdir}. When starting the configuration

$ ${srcdir}/configure --prefix=${destdir} [其它选项]

When installing, remember to replace ${srcdir} and ${destdir} with the real directory. Mine is written like this

$ /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

记得加上后面三个依赖项,否则会出刚开始出现的错误的。然后安装

$ make
$ make install

安装的时候等挺长时间,差不多两个小时。

3.5 gcc、g++、gcj设置

要想使用GCC 4.3.4的gcc等命令,简单的方法就是把它的路径${destdir}/bin放在环境变量PATH中。我不用这种方式,而是用符号连接的方式实现,这样做的好处是我仍然可以使用系统上原来的旧版本的GCC编译器。

而原来gcc的路径是在usr/bin下。我们可以把gcc 4.3.4中的gcc、g++、gcj等命令在/usr/bin目录下分别做一个符号连接:

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

这样,就可以分别使用gcc434、g++434、gcj434来调用GCC 4.1.2的gcc、g++、gcj完成对C、C++、JAVA程序的编译了。同时,仍然能够使用旧版本的GCC编译器中的gcc、g++等命令。

3.6 库路径的设置

将${destdir}/lib路径添加到环境变量LD_LIBRARY_PATH中,例如,如果GCC 4.3.4安装在/usr/local/gcc-4.3.4目录下,在RH Linux下可以直接在命令行上执行

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

最好添加到系统的配置文件中,这样就不必要每次都设置这个环境变量了,在文件$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/lib
export LD_LIBRARY_PATH

或者在/etc/bash_profile 下添加。

重启系统设置生效,或者执行命令

$ source $HOME/.bash_profile

或者:

$ source /etc/bash_profile

用新的编译命令(gcc412、g++412等)编译你以前的C、C++程序,检验新安装的GCC编译器是否能正常工作。

完成了Linux安装GCC,之后你就能轻松地编辑了。

相关学习推荐:linux视频教程

The above is the detailed content of How to install gcc under linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Tutorial on finding keywords for common Linux commandsTutorial on finding keywords for common Linux commandsMar 05, 2025 am 11:45 AM

This tutorial demonstrates efficient keyword searching in Linux using the grep command family and related tools. It covers basic and advanced techniques, including regular expressions, recursive searches, and combining commands like awk, sed, and xa

Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do?Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do?Mar 05, 2025 am 11:37 AM

This article details the multifaceted role of a Linux system administrator, encompassing system maintenance, troubleshooting, security, and collaboration. It highlights essential technical and soft skills, salary expectations, and diverse career pr

How do I configure SELinux or AppArmor to enhance security in Linux?How do I configure SELinux or AppArmor to enhance security in Linux?Mar 12, 2025 pm 06:59 PM

This article compares SELinux and AppArmor, Linux kernel security modules providing mandatory access control. It details their configuration, highlighting the differences in approach (policy-based vs. profile-based) and potential performance impacts

How do I back up and restore a Linux system?How do I back up and restore a Linux system?Mar 12, 2025 pm 07:01 PM

This article details Linux system backup and restoration methods. It compares full system image backups with incremental backups, discusses optimal backup strategies (regularity, multiple locations, versioning, testing, security, rotation), and da

How do I use regular expressions (regex) in Linux for pattern matching?How do I use regular expressions (regex) in Linux for pattern matching?Mar 17, 2025 pm 05:25 PM

The article explains how to use regular expressions (regex) in Linux for pattern matching, file searching, and text manipulation, detailing syntax, commands, and tools like grep, sed, and awk.

How do I monitor system performance in Linux using tools like top, htop, and vmstat?How do I monitor system performance in Linux using tools like top, htop, and vmstat?Mar 17, 2025 pm 05:28 PM

The article discusses using top, htop, and vmstat for monitoring Linux system performance, detailing their unique features and customization options for effective system management.

How do I implement two-factor authentication (2FA) for SSH in Linux?How do I implement two-factor authentication (2FA) for SSH in Linux?Mar 17, 2025 pm 05:31 PM

The article provides a guide on setting up two-factor authentication (2FA) for SSH on Linux using Google Authenticator, detailing installation, configuration, and troubleshooting steps. It highlights the security benefits of 2FA, such as enhanced sec

Methods for uploading files for common Linux commandsMethods for uploading files for common Linux commandsMar 05, 2025 am 11:42 AM

This article compares Linux commands (scp, sftp, rsync, ftp) for uploading files. It emphasizes security (favoring SSH-based methods) and efficiency, highlighting rsync's delta transfer capabilities for large files. The choice depends on file size,

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft