lunix下如何安装8.3.0gcc 以及常见的错误

安装8.3.0gcc

首先安装8.3.0gcc的依赖包

安装gcc需要这三个依赖:GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+。
下载地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/。
找到需要的三个包地址
在这里插入图片描述
解压安装gmp
$tar -jxvf gmp-6.1.0.tar.bz2
$cd gmp-6.1.0
$./configure --prefix=/work/tool/gmp-6.1.0
$make
$make check
$sudo make install
在这里插入图片描述

解压安装mpfr
$tar -jxvf mpfr-3.1.4.tar.bz2
$cd mpfr-3.1.4
//congfigure后面是mpfr安装路径及依赖的gmp路径
$./configure --prefix=/work/tool/mpfr-3.1.4 --with-gmp=/work/tool/gmp-6.1.0
$make
$make check
$sudo make install
在这里插入图片描述配置环境变量

#vi /etc/profile //向/etc/profile文件末尾添加下面的语句(root权限下):
export LD_LIBRARY_PATH=/work/tool/gmp-6.1.0/lib: L D L I B R A R Y P A T H e x p o r t L D L I B R A R Y P A T H = / w o r k / t o o l / m p f r − 3.1.4 / l i b : LD_LIBRARY_PATH export LD_LIBRARY_PATH=/work/tool/mpfr-3.1.4/lib: LDLIBRARYPATHexportLDLIBRARYPATH=/work/tool/mpfr3.1.4/lib:LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/work/tool/mpc-1.0.3/lib:$LD_LIBRARY_PATH

#echo $LD_LIBRARY_PATH //查看配置是否成功
/work/tool/mpc-1.0.3/lib:/work/tool/mpfr-3.1.4/lib:/work/tool/gmp-6.1.0/lib:

#vi /etc/ld.so.conf //编辑这个文件,添加下面路径
/work/tool/gmp-6.1.0/lib
/work/tool/mpfr-3.1.4/lib
/work/tool/mpc-1.0.3/lib
$sudo ldconfig

安装8.3.0gcc

安装链接
链接: http://ftp.gnu.org/gnu/gcc/.
我选的是
在这里插入图片描述传到lunix上 跳转到压缩包所在工作目录 解压




    tar -zxvf gcc-8.3.0.tar.gz

在这里插入图片描述解压成功

进入目录

 cd gcc-8.3.0
配置
./configure --prefix=/work/tool/gcc-8.3.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/work/tool/gmp-6.1.0 --with-mpfr=/work/tool/mpfr-3.1.4 --with-mpc=/work/tool/mpc-1.0.3

安装

 make 

安装成功!
在这里插入图片描述

安装时间非常长!一个小时以上 请耐心等待 然后

  make install

在这里插入图片描述
配置gcc
#vi /etc/profile //向/etc/profile文件末尾添加下面的语句(root权限下):

export PATH=/work/tool/gcc-8.3.0:$PATH

#source /etc/profile //使其立即生效

#rm /usr/bin/gcc //删除旧的软连接
#ln -s /work/tool/gcc-8.3.0/bin/gcc /usr/bin/gcc //使新版本建立软连接

//下面的同理
#rm /usr/bin/g++
#ln -s /work/tool/gcc-8.3.0/bin/g++ /usr/bin/g++
最后
  gcc -v

如果发现版本没有变化,删除旧版本的gcc,yum remove gcc。
在这里插入图片描述
再查看版本,是否已变成最新安装的版本。
在这里插入图片描述安装成功

常见错误

缺少GCC软件套件

可能会出现如下错误

[root@localhost gcc-8.3.0]# ./configure
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for libmpx support... yes
checking for libhsail-rt support... yes
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/work/tool/gcc-8.3.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

``安装GCC软件套件

在这里插入图片描述y下载并安装 d只下载不安装 n既不下载也不安装 选y就好啦

[root@localhost ~]# yum install gcc

在这里插入图片描述完事之后继续

./configure --prefix=/work/tool/gcc-8.3.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/work/tool/gmp-6.1.0 --with-mpfr=/work/tool/mpfr-3.1.4 --with-mpc=/work/tool/mpc-1.0.3

make错误 出现如下错误 缺少依赖包 安装步骤参考上文

checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

   

错误说明,安装gcc需要这三个依赖:GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+。

运行make时还可能出现的错误

configure: error: in `/work/tool/gcc-8.3.0/host-x86_64-pc-linux-gnu/gcc':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details.
make[2]: *** [configure-stage1-gcc] 错误 1
make[2]: 离开目录“/work/tool/gcc-8.3.0”
make[1]: *** [stage1-bubble] 错误 2
make[1]: 离开目录“/work/tool/gcc-8.3.0”
make: *** [all] 错误 2

错误:configure: error: C++ preprocessor “/lib/cpp” fails sanity check
缺少必要的C++库。CentOS系统,运行命令解决:
yum install glibc-headers
yum install gcc-c++
Ubuntu系统中,运行命令:
apt-get install build-essential
apt-get install g++
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/faith_girl/article/details/116036362