linux 7.4安装gcc,在 Centos 7.4 上安装Gcc 7.3

依旧是那个老生常谈的问题,Cent OS上的软件包大都很老,比如常用的Gcc,在最新的Cent OS 7.4上,gcc的版本才到4.8.5,虽说一味追求新版并无大用,但是有些特性老版本不支持啊,很坑的有木有。

下面记录一下安装过程。

描述

系统为Cent OS7.4,全新安装,更新全部软件至最新版。

安装准备1

2yum update -y

yum install gcc gcc-c++ gcc-gnat zlib-devel glibc-devel glibc-devel.i686 libgcc libgcc.i686 -y

安装 glibc-devel.i686 是为了安装32位的头文件和库,否则在配置的时候就会出现下面的错误

1configure: error: I suspect your system does not have 32-bit developement libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

网络上清一色的叫你加入参数--disable-multilib,然而,这样的话就少了32位的支持了。

动手1

2

3

4

5

6

7wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz

tar -zxf gcc-7.3.0.tar.gz

cd gcc-7.3.0

./contrib/download_prerequisites

mkdir builddir && cd builddir

../configure

make && sudo make install

编译过程长达数个小时,具体要多长时间得看RP了,可以用tmux把它放在后台。

需要配置的地方非常少,安装过程也没什么特殊的,但是以前安装gcc的时候随便报个错就一脸懵逼,需要注意的是在./contrib/download_prerequisites之后,会有执行成功的提示,log如下

1

2

3

4

5

6

7

8

92018-04-16 16:37:22 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]

2018-04-16 16:37:28 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]

2018-04-16 16:37:33 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]

2018-04-16 16:37:39 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2 [1626446] -> "./isl-0.16.1.tar.bz2" [1]

gmp-6.1.0.tar.bz2: OK

mpfr-3.1.4.tar.bz2: OK

mpc-1.0.3.tar.gz: OK

isl-0.16.1.tar.bz2: OK

All prerequisites downloaded successfully.

这个步骤是有可能因为网络原因出问题的,这个步骤可以把安装gcc需要的四个依赖包弄好,网络上的某些教程是让你手动安装依赖,比如这个https://www.cnblogs.com/freeweb/p/5990860.html,操作越多越容易出错。

另外,配置同样是需要考虑的地方,大多数时候直接执行./configure就过去了,我用了下面的配置参数

1../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++,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux

选择这个参数并没有什么非常实在的原因,里面很多参数我并不清楚是干嘛的,使用这个参数纯粹是因为Cent OS用yum安装的gcc的配置参数是这个。

安装gdb

在某些情况下,升级了gcc是需要同步升级gdb的,虽然不清楚是否有具体的版本对应关系,但是傻fufu的安装最新版就是了

1

2

3

4

5

6wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gdb/gdb-8.1.tar.gz

tar -zxf gdb-8.1.tar.gz

cd gdb-8.1

mkdir builddir && cd builddir

../configure

make && make install

碎碎念

有可能在执行make install的时候报错(内心PS,都已经编译好了,你给我在安装的时候报错(ノ`Д)ノ)报错信息如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20WARNING: 'makeinfo' is missing on your system.

You should only need it if you modified a '.texi' file, or

any other file indirectly affecting the aspect of the manual.

You might want to install the Texinfo package:

The spurious makeinfo call might also be the consequence of

using a buggy 'make' (AIX, DU, IRIX), in which case you might

want to install GNU make:

make[5]: *** [gdb.info] Error 127

make[5]: Leaving directory `/root/gdb-8.1/build/gdb/doc'

make[4]: *** [subdir_do] Error 1

make[4]: Leaving directory `/root/gdb-8.1/build/gdb'

make[3]: *** [install-only] Error 2

make[3]: Leaving directory `/root/gdb-8.1/build/gdb'

make[2]: *** [install] Error 2

make[2]: Leaving directory `/root/gdb-8.1/build/gdb'

make[1]: *** [install-gdb] Error 2

make[1]: Leaving directory `/root/gdb-8.1/build'

make: *** [install] Error 2

需要yum install texinfo,然后再执行make install。

至于原本安装好的gcc的话,应该是没了吧,我是找不到它了。

安装软件的推荐性是这样的官方源>知名第三方源>手动编译>不知名第三方源,很多时候,手动编译需要自己安装依赖,很多时候,自己安装依赖还会需要安装依赖的依赖,某些极端情况下,还会遇到依赖循环,令人十分的窒息。

自行编译安装并不是很推荐的操作,并且很多时候新版并不一定就更好,Cent OS一直用着老版本的软件并不是没有道理的。

建立builddir的目的,只是为了让编译产生的文件集中在一个地方,免得主目录一大堆文件看起来不方便。

Ubuntu/Debia的软件版本一般都比较新,不值得花大量时间手动编译。

951a3b5fff40f4ceba85f200cf1cb8a9.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值