美文网首页
centos安装gcc

centos安装gcc

作者: expgene | 来源:发表于2023-09-08 16:23 被阅读0次

探序基因肿瘤研究院 整理

安装好centos或ubuntu的linux操作系统后,gcc版本一般比较低。如果我们要编译一些最新的包,有可能旧的gcc编译不了。

我们可以安装新版的gcc到一个新的目录中,以备不时之需。

gcc网址:https://gcc.gnu.org/install/download.html

下载源代码安装包:http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/

根据需要下载了源代码安装包后,解压缩,./configure --prefix=xxx --enable-languages=c,c++,fortran --disable-multilib

注意,需要提前安装(以有root权限为例子),并配置好环境变量:

GMP:

https://gmplib.org

./configure,make,make install

MPFR:

https://www.mpfr.org/mpfr-current/
下载解压缩,进入目录,./configure,make,make install

MPC:

http://ftp.gnu.org/gnu/mpc/

./configure,make,make install

安装顺序:MPFR依赖GMP,MPC依赖GMP和MPFR,GCC依赖上面四个库,所以推荐的编译安装顺序是GMP->MPFR->MPC

总结:

/configure --prefix=/software/GCC1130 --enable-languages=c,c++,fortran --disable-multilib --with-mpc=/mpc131 --with-mpfr=/mpfr421 --with-gmp=/gmp630,但还是出错:

error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory

在/usr/lib64发现,是libmpfr.so.4,libmpfr.so.4.1.6,但在新安装的MPFR目录中,是libmpfr.so.6

于是重新编译,改为:

/configure --prefix=/software/GCC1130 --enable-languages=c,c++,fortran

--disable-multilib --with-mpc-include= --with-mpc-lib= --with-mpfr-include= --with-mpfr-lib --with-gmp-include --with-gmp-lib也不行。

于是编辑vi ~/.bashrc,修改环境变量,

export LD_LIBRARY_PATH=

export LIBRARY_PATH=

export C_INCLUDE_PATH=

export CPLUS_INCLUDE_PATH=

又出现错误:

checking LIBRARY_PATH variable... contains current directory

configure: error:

*** LIBRARY_PATH shouldn't contain the current directory when

*** building gcc. Please change the environment variable

*** and run configure again.

修改了$LD_LIBRARY_PATH变量,也不行。于是将/usr/lib64,/usr/include的旧的mpc,mpfr,gmp都替换成新的,并且清空环境变量。

重新./configure,发现问题:

configure:4546: error: C compiler cannot create executables

运行grep cannot config.log 检查,发现:

/usr/libexec/gcc/x86_64-redhat-linux/8/cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory

于是到/usr/lib64,ln -s libmpfr.so.6.2.1 libmpfr.so.4

再编译就行。

make install后:

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH' environment variable

     during linking

   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

最后配置环境变量,把安装到自己目录的gcc添加到环境变量中:

export PATH=/software/gcc1130/bin:$PATH

export LD_LIBRARY=/software/gcc1130/lib:/software/gcc1130/lib64:$LD_LIBRARY

export LIBRARY_PATH=/software/gcc1130/lib:/software/gcc1130/lib64:$LIBRARY_PATH

export C_INCLUDE_PATH=/software/gcc1130/include:$C_INCLUDE_PATH

export CPLUS_INCLUDE_PATH=/software/gcc1130/include:CPLUS_INCLUDE_PATH

相关文章

网友评论

      本文标题:centos安装gcc

      本文链接:https://www.haomeiwen.com/subject/cbocmdtx.html