因为科研需要,在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步骤如下
- 下载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(三个软件的安装顺序不能乱)
-..
. --- --- ---
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的库。
发现新世界
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)