linux安装c++编译器

[root@localhost /]# yum search gcc

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.neusoft.edu.cn

 * updates: mirrors.nwsuaf.edu.cn

================================== N/S matched: gcc ===================================

gcc-c++.x86_64 : C++ support for GCC

gcc-gnat.x86_64 : Ada 95 support for GCC

gcc-objc.x86_64 : Objective-C support for GCC

gcc-objc++.x86_64 : Objective-C++ support for GCC

gcc-plugin-devel.x86_64 : Support for compiling GCC plugins

libgcc.x86_64 : GCC version 4.8 shared support library

libgcc.i686 : GCC version 4.8 shared support library

relaxngcc-javadoc.noarch : Javadoc for relaxngcc

compat-gcc-44.x86_64 : Compatibility GNU Compiler Collection

compat-gcc-44-c++.x86_64 : C++ support for compatibility compiler

compat-gcc-44-gfortran.x86_64 : Fortran support for compatibility compiler

gcc.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)

gcc-gfortran.x86_64 : Fortran support

gcc-go.x86_64 : Go support

libgomp.x86_64 : GCC OpenMP v3.0 shared support library

libgomp.i686 : GCC OpenMP v3.0 shared support library

libmudflap.i686 : GCC mudflap shared support library

libmudflap.x86_64 : GCC mudflap shared support library

libmudflap-devel.i686 : GCC mudflap support

libmudflap-devel.x86_64 : GCC mudflap support

libquadmath.i686 : GCC __float128 shared support library

libquadmath.x86_64 : GCC __float128 shared support library

libquadmath-devel.i686 : GCC __float128 support

libquadmath-devel.x86_64 : GCC __float128 support

relaxngcc.noarch : RELAX NG Compiler Compiler

  名称和简介匹配 only,使用“search all”试试。

[root@localhost /]# yum install gcc-c++ -y

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.neusoft.edu.cn

 * updates: mirrors.nwsuaf.edu.cn

正在解决依赖关系

--> 正在检查事务

---> 软件包 gcc-c++.x86_64.0.4.8.5-28.el7_5.1 将被 安装

--> 正在处理依赖关系 libstdc++-devel = 4.8.5-28.el7_5.1,它被软件包 gcc-c++-4.8.5-28.el7_5.1.x86_64 需要

--> 正在处理依赖关系 libstdc++ = 4.8.5-28.el7_5.1,它被软件包 gcc-c++-4.8.5-28.el7_5.1.x86_64 需要

--> 正在处理依赖关系 gcc = 4.8.5-28.el7_5.1,它被软件包 gcc-c++-4.8.5-28.el7_5.1.x86_64 需要

--> 正在处理依赖关系 libmpc.so.3()(64bit),它被软件包 gcc-c++-4.8.5-28.el7_5.1.x86_64 需要

--> 正在检查事务

---> 软件包 gcc.x86_64.0.4.8.5-28.el7_5.1 将被 安装

--> 正在处理依赖关系 libgomp = 4.8.5-28.el7_5.1,它被软件包 gcc-4.8.5-28.el7_5.1.x86_64 需要

--> 正在处理依赖关系 cpp = 4.8.5-28.el7_5.1,它被软件包 gcc-4.8.5-28.el7_5.1.x86_64 需要

--> 正在处理依赖关系 libgcc >= 4.8.5-28.el7_5.1,它被软件包 gcc-4.8.5-28.el7_5.1.x86_64 需要

--> 正在处理依赖关系 glibc-devel >= 2.2.90-12,它被软件包 gcc-4.8.5-28.el7_5.1.x86_64 需要

---> 软件包 libmpc.x86_64.0.1.0.1-3.el7 将被 安装

---> 软件包 libstdc++.x86_64.0.4.8.5-16.el7 将被 升级

---> 软件包 libstdc++.x86_64.0.4.8.5-28.el7_5.1 将被 更新

---> 软件包 libstdc++-devel.x86_64.0.4.8.5-28.el7_5.1 将被 安装

--> 正在检查事务

---> 软件包 cpp.x86_64.0.4.8.5-28.el7_5.1 将被 安装

---> 软件包 glibc-devel.x86_64.0.2.17-222.el7 将被 安装

--> 正在处理依赖关系 glibc-headers = 2.17-222.el7,它被软件包 glibc-devel-2.17-222.el7.x86_64 需要

--> 正在处理依赖关系 glibc = 2.17-222.el7,它被软件包 glibc-devel-2.17-222.el7.x86_64 需要

--> 正在处理依赖关系 glibc-headers,它被软件包 glibc-devel-2.17-222.el7.x86_64 需要

---> 软件包 libgcc.x86_64.0.4.8.5-16.el7 将被 升级

---> 软件包 libgcc.x86_64.0.4.8.5-28.el7_5.1 将被 更新

---> 软件包 libgomp.x86_64.0.4.8.5-16.el7 将被 升级

---> 软件包 libgomp.x86_64.0.4.8.5-28.el7_5.1 将被 更新

--> 正在检查事务

---> 软件包 glibc.x86_64.0.2.17-196.el7 将被 升级

--> 正在处理依赖关系 glibc = 2.17-196.el7,它被软件包 glibc-common-2.17-196.el7.x86_64 需要

---> 软件包 glibc.x86_64.0.2.17-222.el7 将被 更新

---> 软件包 glibc-headers.x86_64.0.2.17-222.el7 将被 安装

--> 正在处理依赖关系 kernel-headers >= 2.2.1,它被软件包 glibc-headers-2.17-222.el7.x86_64 需要

--> 正在处理依赖关系 kernel-headers,它被软件包 glibc-headers-2.17-222.el7.x86_64 需要

--> 正在检查事务

---> 软件包 glibc-common.x86_64.0.2.17-196.el7 将被 升级

---> 软件包 glibc-common.x86_64.0.2.17-222.el7 将被 更新

---> 软件包 kernel-headers.x86_64.0.3.10.0-862.14.4.el7 将被 安装

--> 解决依赖关系完成

依赖关系解决

=======================================================================================

 Package                架构          版本                        源              大小

=======================================================================================

正在安装:

 gcc-c++                x86_64        4.8.5-28.el7_5.1            updates        7.2 M

为依赖而安装:

 cpp                    x86_64        4.8.5-28.el7_5.1            updates        5.9 M

 gcc                    x86_64        4.8.5-28.el7_5.1            updates         16 M

 glibc-devel            x86_64        2.17-222.el7                base           1.1 M

 glibc-headers          x86_64        2.17-222.el7                base           678 k

 kernel-headers         x86_64        3.10.0-862.14.4.el7         updates        7.1 M

 libmpc                 x86_64        1.0.1-3.el7                 base            51 k

 libstdc++-devel        x86_64        4.8.5-28.el7_5.1            updates        1.5 M

为依赖而更新:

 glibc                  x86_64        2.17-222.el7                base           3.6 M

 glibc-common           x86_64        2.17-222.el7                base            11 M

 libgcc                 x86_64        4.8.5-28.el7_5.1            updates        101 k

 libgomp                x86_64        4.8.5-28.el7_5.1            updates        156 k

 libstdc++              x86_64        4.8.5-28.el7_5.1            updates        303 k

事务概要

=======================================================================================

安装  1 软件包 (+7 依赖软件包)

升级           ( 5 依赖软件包)

总下载量:55 M

Downloading packages:

No Presto metadata available for base

Not downloading deltainfo for updates, MD is 679 k and rpms are 560 k

警告:/var/cache/yum/x86_64/7/base/packages/glibc-2.17-222.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY

glibc-2.17-222.el7.x86_64.rpm 的公钥尚未安装

(1/13): glibc-2.17-222.el7.x86_64.rpm                           | 3.6 MB  00:00:30     

gcc-c++-4.8.5-28.el7_5.1.x86_64.rpm 的公钥尚未安装   ] 371 kB/s |  18 MB  00:01:42 ETA 

(2/13): gcc-c++-4.8.5-28.el7_5.1.x86_64.rpm                     | 7.2 MB  00:00:50     

(3/13): glibc-headers-2.17-222.el7.x86_64.rpm                   | 678 kB  00:00:07     

(4/13): glibc-common-2.17-222.el7.x86_64.rpm                    |  11 MB  00:01:16     

(5/13): libgcc-4.8.5-28.el7_5.1.x86_64.rpm                      | 101 kB  00:00:12     

(6/13): libgomp-4.8.5-28.el7_5.1.x86_64.rpm                     | 156 kB  00:00:02     

(7/13): glibc-devel-2.17-222.el7.x86_64.rpm                     | 1.1 MB  00:01:04     

(8/13): cpp-4.8.5-28.el7_5.1.x86_64.rpm                         | 5.9 MB  00:01:36     

(9/13): libstdc++-4.8.5-28.el7_5.1.x86_64.rpm                   | 303 kB  00:00:03     

(10/13): libstdc++-devel-4.8.5-28.el7_5.1.x86_64.rpm            | 1.5 MB  00:00:08     

libmpc-1.0.1-3.el7.x86_64.rpm  FAILED                                          :28 ETA 

http://centos.ustc.edu.cn/centos/7.5.1804/os/x86_64/Packages/libmpc-1.0.1-3.el7.x86_64.rpm: [Errno 12] Timeout on http://centos.ustc.edu.cn/centos/7.5.1804/os/x86_64/Packages/libmpc-1.0.1-3.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')

正在尝试其它镜像。

(11/13): libmpc-1.0.1-3.el7.x86_64.rpm                          |  51 kB  00:00:04     

(12/13): gcc-4.8.5-28.el7_5.1.x86_64.rpm                        |  16 MB  00:02:20     

(13/13): kernel-headers-3.10.0-862.14.4.el7.x86_64.rpm          | 7.1 MB  00:01:38     

---------------------------------------------------------------------------------------

总计                                                      361 kB/s |  55 MB  02:37     

从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥

导入 GPG key 0xF4A80EB5:

 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"

 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5

 软件包     : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)

 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在更新    : libgcc-4.8.5-28.el7_5.1.x86_64                                    1/18 

  正在更新    : glibc-common-2.17-222.el7.x86_64                                  2/18 

  正在更新    : glibc-2.17-222.el7.x86_64                                         3/18 

  正在安装    : libmpc-1.0.1-3.el7.x86_64                                         4/18 

  正在更新    : libstdc++-4.8.5-28.el7_5.1.x86_64                                 5/18 

  正在安装    : libstdc++-devel-4.8.5-28.el7_5.1.x86_64                           6/18 

  正在安装    : cpp-4.8.5-28.el7_5.1.x86_64                                       7/18 

  正在更新    : libgomp-4.8.5-28.el7_5.1.x86_64                                   8/18 

  正在安装    : kernel-headers-3.10.0-862.14.4.el7.x86_64                         9/18 

  正在安装    : glibc-headers-2.17-222.el7.x86_64                                10/18 

  正在安装    : glibc-devel-2.17-222.el7.x86_64                                  11/18 

  正在安装    : gcc-4.8.5-28.el7_5.1.x86_64                                      12/18 

  正在安装    : gcc-c++-4.8.5-28.el7_5.1.x86_64                                  13/18 

  清理        : libstdc++-4.8.5-16.el7.x86_64                                    14/18 

  清理        : libgomp-4.8.5-16.el7.x86_64                                      15/18 

  清理        : glibc-common-2.17-196.el7.x86_64                                 16/18 

  清理        : glibc-2.17-196.el7.x86_64                                        17/18 

  清理        : libgcc-4.8.5-16.el7.x86_64                                       18/18 

  验证中      : libgomp-4.8.5-28.el7_5.1.x86_64                                   1/18 

  验证中      : libgcc-4.8.5-28.el7_5.1.x86_64                                    2/18 

  验证中      : libstdc++-devel-4.8.5-28.el7_5.1.x86_64                           3/18 

  验证中      : gcc-4.8.5-28.el7_5.1.x86_64                                       4/18 

  验证中      : glibc-devel-2.17-222.el7.x86_64                                   5/18 

  验证中      : cpp-4.8.5-28.el7_5.1.x86_64                                       6/18 

  验证中      : glibc-headers-2.17-222.el7.x86_64                                 7/18 

  验证中      : kernel-headers-3.10.0-862.14.4.el7.x86_64                         8/18 

  验证中      : libmpc-1.0.1-3.el7.x86_64                                         9/18 

  验证中      : glibc-common-2.17-222.el7.x86_64                                 10/18 

  验证中      : libstdc++-4.8.5-28.el7_5.1.x86_64                                11/18 

  验证中      : glibc-2.17-222.el7.x86_64                                        12/18 

  验证中      : gcc-c++-4.8.5-28.el7_5.1.x86_64                                  13/18 

  验证中      : libgcc-4.8.5-16.el7.x86_64                                       14/18 

  验证中      : libstdc++-4.8.5-16.el7.x86_64                                    15/18 

  验证中      : glibc-common-2.17-196.el7.x86_64                                 16/18 

  验证中      : glibc-2.17-196.el7.x86_64                                        17/18 

  验证中      : libgomp-4.8.5-16.el7.x86_64                                      18/18 

已安装:

  gcc-c++.x86_64 0:4.8.5-28.el7_5.1                                                    

作为依赖被安装:

  cpp.x86_64 0:4.8.5-28.el7_5.1                  gcc.x86_64 0:4.8.5-28.el7_5.1         

  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    libmpc.x86_64 0:1.0.1-3.el7           

  libstdc++-devel.x86_64 0:4.8.5-28.el7_5.1     

作为依赖被升级:

  glibc.x86_64 0:2.17-222.el7                glibc-common.x86_64 0:2.17-222.el7       

  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       

完毕!

[root@localhost /]# 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) 

[root@localhost /]# ls

bin   dev  home  lib64  mnt  pause.png  root  sbin  sys  usr

boot  etc  lib   media  opt  proc       run   srv   tmp  var

[root@localhost /]# cd home

[root@localhost home]# ls

xqx

[root@localhost home]# mkdir c++

[root@localhost home]# cd c++

[root@localhost c++]# ls

[root@localhost c++]# touch test.cpp

[root@localhost c++]# vim test.cpp

#include<iostream>

int main(int argc,char * argv[])

{

  std::cout<<"running\n";

  return 0;

}

[root@localhost c++]# g++ -Wall test.cpp -o test   说明:-Wall显示警告信息  -o则是输出成可执行文件

[root@localhost c++]# chmod u+x test  只授予这个文件的所属者执行的权限

[root@localhost c++]# ./test 运行生成的test可执行文件

running

[root@localhost c++]# ls -l

总用量 16

-rwxr-xr-x. 1 root root 8968 11月  1 00:09 test

-rw-r--r--. 1 root root   94 11月  1 00:08 test.cpp

[root@localhost c++]# 

猜你喜欢

转载自blog.csdn.net/weixin_41808843/article/details/88979823