linux 安裝gcc---GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+

burlingame發表於2024-06-25

參考連結:
https://blog.csdn.net/enson16855/article/details/52205044


編譯高版本gcc,執行下面配置命令時,

../configure --prefix=/usr/local/gcc-10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib

報錯如下:

adams@adams-pc:~/tmp/gcc/gcc-10.2.0/build$ ../configure --prefix=/usr/local/gcc-10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
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 libhsail-rt support... yes
checking for libphobos support... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... yes
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... yes
checking for the correct version of mpc.h... no
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.
adams@adams-pc:~/tmp/gcc/gcc-10.2.0/build$ 

根據報錯資訊可以知道,是GMP,MPFR和MPC版本太低導致的上述問題。

所以需要編譯出高版本,然後在編譯gcc時指定路徑,使其在編譯時可以找到高版本的庫以及標頭檔案。

GMP編譯

下載地址:
ftp://ftp.gnu.org/gnu/gmp/

我們選擇gmp-5.0.1.tar.bz2版本進行下載。

wget ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2
tar -vxf gmp-5.0.1.tar.bz2
cd gmp-5.0.1/
./configure --prefix=/usr/local/gmp-5.0.1
make
sudo make install
MPFR編譯

下載地址:
https://ftp.gnu.org/gnu/mpfr/

我們選擇mpfr-3.1.5.tar.xz版本進行下載。

wget https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.5.tar.xz
tar -vxf mpfr-3.1.5.tar.gz
cd mpfr-3.1.5/
./configure --prefix=/usr/local/mpfr-3.1.5 --with-gmp=/usr/local/gmp-5.0.1
make
sudo make install
MPC編譯

下載地址:
http://www.multiprecision.org/mpc/download.html

我們選擇mpc-0.9.tar.gz版本進行下載。

wget http://www.multiprecision.org/downloads/mpc-0.9.tar.gz
tar -vxf mpc-0.9.tar.gz
cd mpc-0.9/
./configure --prefix=/usr/local/mpc-0.9 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5
make
sudo make install

這次就可以配置成功了!

../configure --prefix=/usr/local/gcc-10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-0.9
make 
make install

最後設定環境變數:

export PATH=/Bioinfo/SoftWare/gcc-4.8.5/bin:$PATH
export LD_LIBRARY_PATH=/Bioinfo/SoftWare/gcc-4.8.5/lib64:$LD_LIBRARY_PATH

gnu-gmp安裝包下載_開源映象站-阿里雲 (aliyun.com)

gnu-mpfr安裝包下載_開源映象站-阿里雲 (aliyun.com)

gnu-mpc安裝包下載_開源映象站-阿里雲 (aliyun.com)

gnu-gcc-gcc-14.1.0安裝包下載_開源映象站-阿里雲 (aliyun.com)

參考:系統與編譯相關 - 非 root 使用者手動編譯安裝 GCC - 《技術私房菜》 - 極客文件 (geekdaxue.co)

相關文章