在centOS6.8下更新安装gcc4.7.4

因为科研需要,在centOS6.8系统下配置matlab与C混合编程的环境(用C来调用MATLAB引擎)。MATLAB安装的是R2015b的版本(之前安装R2014a版本,没办法启动MATLAB引擎),用gcc调用MATLAB一直失败。后来发现原因是centOS6.8的gcc是4.4.7版本,而R2015b需要gcc4.7版本,编译器与MATLAB版本不兼容导致。不同版本的MATLAB兼容的gcc版本可以从mathwork官网查得。

在centOS6.8下更新安装gcc4.7.4步骤如下

  1. 下载gcc源码。在gcc官网找到需要下载的源码压缩包,比如http://mirrors.concertpass.com/gcc/releases/gcc-4.7.4/gcc-4.7.4.tar.gz右键,复制链接地址。进入/opt文件夹,下载源码,解压缩。

wget 右键复制的网址

tar xf gcc-4.7.4.tar.gz

2.安装gcc之前需要安装GMP,MPFR和MPC,这三个软件可以用gcc自带的脚本进行下载。


cd /opt/gcc-4.7.4/contrib/

./download_prerequisites

3.建立一个和gcc-4.7.4文件夹平行的文件夹gccinstalldir,在此文件夹下建立gcc-build,pre-build两个文件夹作为安装目录。


mkdir /opt/gccinstalldir

mkdir /opt/gccinstalldir/gcc-build /opt/gccinstalldir/pre-build

4.先安装GMP(三个软件的安装顺序不能乱)


cd /opt/gcc-4.7.4/contrib/gmp

./configure --disable-shared --enable-static --prefix=/opt/gccinstalldir/pre-build/

make

make check

make install

5.安装MPFR


cd /opt/gcc-4.7.4/contrib/mpfr

./configure --disable-shared --enable-static --prefix=/opt/gccinstalldir/pre-build/  --with-gmp=/opt/gccinstalldir/pre-build/

make

make check

make install

6.安装MPC


./configure --disable-shared --enable-static --prefix=/opt/gccinstalldir/pre-build/  --with-gmp=/opt/gccinstalldir/pre-build/  --with-mpfr=/opt/gccinstalldir/pre-build/

make

make check

make install

7.最后就是安装gcc了


cd /opt/gcc-4.7.4

./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib  --prefix=/opt/gccinstalldir/gcc-build/ --with-gmp=/opt/gccinstalldir/pre-build/ --with-mpfr=/opt/gccinstalldir/pre-build/ --with-mpc=/opt/gccinstalldir/pre-build/

make -j3

make check

make install

make -j3是用三个进程来编译,否则会很慢,也可以改成其他的数字。

这样gcc4.7就安装好了。需要注意的是现在的gcc是安装在了/opt/gccinstalldir/gcc-build文件夹中,默认的gcc依然是之前的gcc4.4版本。如果想用4.7版本需要指明用/opt/gccinstalldir/gcc-build/bin/gcc,也要指明用gcc4.7的库。

发现新世界

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值