随记--Redhat7.6在x86环境下安装gcc与g++编译环境

目录

 

一、GCC与G++

二、检查是否已安装

三、安装GCC与G++

第一步:需要的安装包

第二步:安装


一、GCC与G++

GCC 与G++ : 

        gcc 起初是指 GNU C Compiler,就是一个c编译器。但是后来因为这个项目里边集成了许多其他不同语言的编译器,GCC就代表 the GNU Compiler Collection,所以表示一堆编译器的合集。

      g++则是GCC的c++编译器。

二、检查是否已安装

验证redhat系统中是否有gcc与g++

[root@localhost cfiles]# gcc -v
bash: gcc: command not found...
[root@localhost cfiles]# g++ -v
bash: g++: command not found...

如上可以看到,没有gcc与g++的编译环境。如果已安装了这些环境,执行命令如下效果:

[root@localhost gcc]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
[root@localhost gcc]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 

可以看到版本、安装位置等信息。

三、安装GCC与G++

第一步:需要的安装包

       kernel-headers-3.10.0-957.el7.x86_64.rpm

       glibc-headers-2.17-260.el7.x86_64.rpm

       glibc-devel-2.17-260.el7.x86_64.rpm 

       cpp-4.8.5-36.el7.x86_64.rpm

       binutils-2.27-34.base.el7.x86_64.rpm

       gcc-4.8.5-36.el7.x86_64.rpm                    ---GCC安装包

       libstdc++-devel-4.8.5-36.el7.x86_64.rpm

       gcc-c++-4.8.5-36.el7.x86_64.rpm             ----G++安装包

上述安装及依赖包都可以在redhat7.6的镜像文件中找到

       随记--Redhat7.6在x86环境下安装gcc与g++编译环境_第1张图片

第二步:安装

使用 rpm -ivh   安装包XXX.rpm 进行安装,执行顺序如上安装包顺序从上到下依次执行

[root@localhost gcc]# ll
total 47568
-rw-r--r--. 1 root root  6189388 Apr 27 09:36 binutils-2.27-34.base.el7.x86_64.rpm
-rw-r--r--. 1 root root  6240300 Apr 27 09:36 cpp-4.8.5-36.el7.x86_64.rpm
-rw-r--r--. 1 root root 16974492 Apr 27 09:36 gcc-4.8.5-36.el7.x86_64.rpm
-rw-r--r--. 1 root root  7532800 Apr 27 09:36 gcc-c++-4.8.5-36.el7.x86_64.rpm
-rw-r--r--. 1 root root  1120840 Apr 27 09:36 glibc-devel-2.17-260.el7.x86_64.rpm
-rw-r--r--. 1 root root   699448 Apr 27 09:36 glibc-headers-2.17-260.el7.x86_64.rpm
-rw-r--r--. 1 root root  8355248 Apr 27 09:36 kernel-headers-3.10.0-957.el7.x86_64.rpm
-rw-r--r--. 1 root root  1580084 Apr 27 09:36 libstdc++-devel-4.8.5-36.el7.x86_64.rpm
[root@localhost gcc]# rpm -ivh kernel-headers-3.10.0-957.el7.x86_64.rpm 
warning: kernel-headers-3.10.0-957.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:kernel-headers-3.10.0-957.el7    ################################# [100%]
[root@localhost gcc]# rpm -ivh glibc-headers-2.17-260.el7.x86_64.rpm 
warning: glibc-headers-2.17-260.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:glibc-headers-2.17-260.el7       ################################# [100%]
[root@localhost gcc]# rpm -ivh glibc-devel-2.17-260.el7.x86_64.rpm 
warning: glibc-devel-2.17-260.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:glibc-devel-2.17-260.el7         ################################# [100%]
[root@localhost gcc]# rpm -ivh cpp-4.8.5-36.el7.x86_64.rpm 
warning: cpp-4.8.5-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:cpp-4.8.5-36.el7                 ################################# [100%]
[root@localhost gcc]# rpm -ivh binutils-2.27-34.base.el7.x86_64.rpm 
warning: binutils-2.27-34.base.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
	package binutils-2.27-34.base.el7.x86_64 is already installed
[root@localhost gcc]# rpm -ivh gcc-4.8.5-36.el7.x86_64.rpm 
warning: gcc-4.8.5-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gcc-4.8.5-36.el7                 ################################# [100%]
[root@localhost gcc]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
[root@localhost gcc]# rpm -ivh libstdc++-devel-4.8.5-36.el7.x86_64.rpm 
warning: libstdc++-devel-4.8.5-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:libstdc++-devel-4.8.5-36.el7     ################################# [100%]
[root@localhost gcc]# rpm -ivh gcc-c++-4.8.5-36.el7.x86_64.rpm 
warning: gcc-c++-4.8.5-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gcc-c++-4.8.5-36.el7             ################################# [100%]

[root@localhost gcc]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
[root@localhost gcc]#

如果安装过程中出现类似如下的错误:

         [root@localhost gcc]# rpm -ivh gcc-c++-4.8.5-36.el7.x86_64.rpm 
warning: gcc-c++-4.8.5-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
error: Failed dependencies:
    libstdc++-devel = 4.8.5-36.el7 is needed by gcc-c++-4.8.5-36.el7.x86_64

   这个错误是安装gcc-c++-4.8.5-36.el7.x86_64是需要依赖libstdc++-devel,所以先找到libstdc++-devel的安装包将libstdc++-devel安装好,在安装gcc-c++-4.8.5-36.el7.x86_64即可。

error: Failed dependencies:
    被依赖的软件 = 版本号  is needed by 安装的软件              

只需要安装好需要的依赖即可

 

你可能感兴趣的:(随记)