编译gccgo遇到的Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+问题记录

项目场景:

aarch64下基于Kylin V10操作系统编译gccgo

git clone --branch devel/gccgo git://gcc.gnu.org/git/gcc.git gccgo
mkdir objdir
cd objdir
../configure --prefix=/usr/local/gccgo --enable-languages=c,c++,go --with-ld=/usr/bin/ld
make
make install

遇到如下问题:
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.


问题描述

问题详见:

configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.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
https://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.

原因分析:

通过报错信息,需要指定gmp、mpfr、mpc等环境变量,通过包安装器安装或者通过源码编译安装亦可,我们采用源码编译安装方式,
通过查看./contrib/download_prerequisites文件可以看到对应的相关版本如下:

gmp='gmp-6.2.1.tar.bz2'
mpfr='mpfr-4.1.0.tar.bz2'
mpc='mpc-1.2.1.tar.gz'
isl='isl-0.24.tar.bz2'

根据提示里面的网址:https://gcc.gnu.org/pub/gcc/infrastructure/进行wget下载,进行编译安装
例如:wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2


解决方案:

GMP编译

tar -xvf gmp-6.2.1.tar.bz2
cd gmp-6.2.1
./configure --prefix=/usr/local/gmp-6.2.1
make
make install

MPFR编译

tar -xvf mpfr-4.1.0.tar.bz2
cd mpfr-4.1.0
./configure --prefix=/usr/local/mpfr-4.1.0 --with-gmp=/usr/local/gmp-6.2.1
make 
make install

MPC编译

tar -xvf mpc-1.2.1.tar.gz
cd mpc-1.2.1
./configure --prefix=/usr/local/mpc-1.2.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0
make
make install

gccgo 编译

../configure --prefix=/usr/local/gccgo --enable-languages=c,c++,go --with-ld=/usr/bin/ld --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1
make -j64
make install

配置环境变量,即可使用gccgo

export go_version=/usr/local/gccgo
export LD_LIBRARY_PATH=$go_version/lib64:$go_version/lib:$LD_LIBRARY_PATH
export PATH=${go_version}/bin/:$PATH
export GOROOT=${go_version}/

直接编译gccgo是为了迂回解决在aarch64下go的源码编译问题,高版本go的编译需要用到1.4版本,所以需要先编译1.4,但1.4版本对arm支持不好,还需要用到交叉编译。由于目前我所使用的场景的aarch64对go支持不完全,直接采用交叉编译或者官方go存在问题,故需要编译gccgo处理。

问题记录

  • ibmpfr.so.6: cannot open shared object file: No such file or directory
cp doc/gcc.1 doc/g++.1
/opt/gccgo/objdir/./gcc/xgcc -B/opt/gccgo/objdir/./gcc/ -xc -nostdinc /dev/null -S -o /dev/null -fself-test=../../gcc/testsuite/selftests
/opt/gccgo/objdir/./gcc/cc1: error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory
make[3]: *** [../../gcc/c/Make-lang.in:128:s-selftest-c] 错误 1
rm gcov.pod fsf-funding.pod lto-dump.pod gfdl.pod gpl.pod cpp.pod gcov-dump.pod gcc.pod gcov-tool.pod
make[3]: 离开目录“/opt/gccgo/objdir/gcc”
make[2]: *** [Makefile:4963:all-stage1-gcc] 错误 2
make[2]: 离开目录“/opt/gccgo/objdir”
make[1]: *** [Makefile:27234:stage1-bubble] 错误 2
make[1]: 离开目录“/opt/gccgo/objdir”

解决方法:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpfr-4.1.0/lib/

解决文献:

https://blog.csdn.net/weixin_38184741/article/details/107682135
https://go.dev/doc/install/gccgo

你可能感兴趣的:(云计算,linux,服务器,go)