CentOS 7.5下在线yum安装GCC与G++


GCC(GNU Compiler Collection)是Linux下最主要的编译工具,GCC不仅功能非常强大,结构也非常灵活。它可以通过不同的前端模块来支持各种语言,如Java、Fortran、Pascal、Modula-3和Ada。

在CentOS下,可以在联网状态下在线yum安装GCC,但是此种方式安装的GCC是4.8.5版本的,有时候已经不能满足需要。因此还需在此基础上进行升级。截止目前已经有5.0以上的最新版本了,GCC 4.8 开始全面支持C 11和C++ 11的新特性。

先查看下CentOS系统有没有安装GCC与G++。

打开终端输入gcc -v或者:g++ -v

CentOS 7.5下在线yum安装GCC与G++

显示没有安装,下面开始安装。

使用yum安装gcc与g++

在有网络连接条件下进行分别执行如下命令:

#安装gcc、c++编译器以及内核文件

[linuxidc@localhost linuxboy.net]$ sudo yum -y install gcc gcc-c++ kernel-devel

输出:

已安装:
  gcc.x86_64 0:4.8.5-28.el7_5.1              gcc-c++.x86_64 0:4.8.5-28.el7_5.1
  kernel-devel.x86_64 0:3.10.0-862.14.4.el7

作为依赖被安装:
  glibc-devel.x86_64 0:2.17-222.el7                                           
  glibc-headers.x86_64 0:2.17-222.el7                                         
  kernel-headers.x86_64 0:3.10.0-862.14.4.el7                                 
  libstdc++-devel.x86_64 0:4.8.5-28.el7_5.1                                   

作为依赖被升级:
  cpp.x86_64 0:4.8.5-28.el7_5.1        libgcc.x86_64 0:4.8.5-28.el7_5.1     
  libgomp.x86_64 0:4.8.5-28.el7_5.1    libstdc++.x86_64 0:4.8.5-28.el7_5.1   

完毕!

CentOS 7.5下在线yum安装GCC与G++

#如果没有安装make:

yum install make

查看下,默认已经安装好了。

[linuxidc@localhost linuxboy.net]$ make -v
GNU Make 3.82
Built for x86_64-RedHat-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

CentOS 7.5下在线yum安装GCC与G++

#验证安装成功的方法:

[linuxidc@localhost linuxboy.net]$ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)

CentOS 7.5下在线yum安装GCC与G++

或者:

[linuxidc@localhost linuxboy.net]$ g++ -v
使用内建 specs。
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)

CentOS 7.5下在线yum安装GCC与G++

如果显示的gcc版本仍是以前的版本,可以重启系统; 

#查看gcc的安装位置:which gcc;

[linuxidc@localhost linuxboy.net]$ which gcc
/usr/bin/gcc

CentOS 7.5下在线yum安装GCC与G++

测试一个C程序:

#include<stdio.h>

int main()
{
printf("\nlinuxboy(www.linuxboy.net)是专业的Linux系统门户网站\n\n");
return 0;
}

CentOS 7.5下在线yum安装GCC与G++

OK。

在线安装这里没有对gmp、mpfr、mpc等软件分别进行解压和编译,而是直接由download_prerequisites负责下载并解压,最后和gcc一起进行编译安装,这是官方推荐的做法。

linuxboy的RSS地址:https://www.linuxboy.net/rssFeed.aspx

本文永久更新链接地址:https://www.linuxboy.net/Linux/2018-10/155041.htm

相关内容