【转】gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+

本文详细记录了从SVN获取GCC最新代码并编译的过程,解决了配置问题,介绍了GMP、MPFR和MPC三个依赖库的安装步骤,最终成功编译并配置GCC,准备开始C++11的学习。

原文:https://blog.youkuaiyun.com/enson16855/article/details/52205044 

 从svn checkout svn://gcc.gnu.org/svn/gcc/trunk拿了GCC的最新代码,打算编译了学东西习学习C++ 11的东西,结果在configure的时候出现如下问题:

    Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+

    http://www.multiprecision.org/mpc 下载mpc-0.9.tar.gz      

      ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2下载gmp-5.0.1.tar.bz2

      http://ftp.gnu.org/gnu/mpfr/下载mpfr-3.1.0.tar.xz。

     先开始安装GMP。解压GMP的压缩包后,得到源代码目录gmp-5.0.1。在该目录的同级目录下建立一个临时的编译目录,这里命名为temp。然后开始配置安装选项,进入temp目录,输入以下命令进行配置:

  ../gmp-5.0.1/configure –prefix=/usr/local/gmp-5.0.1

     make

     sudo make install

     mpfr和mpc的安装方法与gmp类似。不过要注意配置的时候要把gmp与mpfr的依赖关系选项加进去,具体配置命令如下:

  ../mpfr-3.1.0/configure –prefix=/usr/local/mpfr-3.1.0 –with-gmp=/usr/local/gmp-5.0.1

  ../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.0

  安装好这三个库之后,就可以正式开始安装gcc了。  

     当然了链接的时候,需要刚刚编译的3个lib。

     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.9/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-3.1.0/lib 

     然后是典型的configure,make,install三步曲。

     ../trunk/configure –prefix=/usr/local/gcc-4.7 –enable-threads=posix –disable-checking –disable-multilib –enable-languages=c,c++

  –with-gmp=/usr/local/gmp-5.0.1 –with-mpfr=/usr/local/mpfr-3.1.0 –with-mpc=/usr/local/mpc-0.9

      make

      make check(可选)

      sudo make install

     经过漫长的等待:

 /usr/local/gcc-4.7/bin/g++ -v

使用内建 specs。

COLLECT_GCC=/usr/local/gcc-4.7/bin/g++

COLLECT_LTO_WRAPPER=/usr/local/gcc-4.7/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper

目标:x86_64-unknown-linux-gnu

配置为:../trunk/configure –prefix=/usr/local/gcc-4.7 –enable-threads=posix –disable-checking –disable-multilib –enable-languages=c,c++ –with-gmp=/usr/local/gmp-5.0.1 –with-mpfr=/usr/local/mpfr-3.1.0 –with-mpc=/usr/local/mpc-0.9

线程模型:posix

gcc 版本 4.7.0 20120113 (experimental) (GCC)

开始C++ 11学习了。

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 2.3.1+ 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. Makefile:46: recipe for target '/home/user/nvr8064/torchlight/build_dir/toolchain-arm_gcc-4.6-linaro_uClibc-0.9.33.2_eabi/gcc-linaro-4.6-2012.02-minimal/.configured' failed make[3]: *** [/home/user/nvr8064/torchlight/build_dir/toolchain-arm_gcc-4.6-linaro_uClibc-0.9.33.2_eabi/gcc-linaro-4.6-2012.02-minimal/.configured] Error 1 make[3]: Leaving directory '/home/user/nvr8064/torchlight/toolchain/gcc/minimal' toolchain/Makefile:168: recipe for target 'toolchain/gcc/minimal/compile' failed make[2]: *** [toolchain/gcc/minimal/compile] Error 2 make[2]: Leaving directory '/home/user/nvr8064/torchlight' toolchain/Makefile:132: recipe for target '/home/user/nvr8064/torchlight/staging_dir/toolchain-arm_gcc-4.6-linaro_uClibc-0.9.33.2_eabi/stamp/.toolchain_install' failed make[1]: *** [/home/user/nvr8064/torchlight/staging_dir/toolchain-arm_gcc-4.6-linaro_uClibc-0.9.33.2_eabi/stamp/.toolchain_install] Error 2 make[1]: Leaving directory '/home/user/nvr8064/torchlight' /home/user/nvr8064/torchlight/include/toplevel.mk:199: recipe for target 'world' failed make: *** [world] Error 2 这次报这个错误了
最新发布
12-24
<think>好的,我现在需要帮助用户解决在构建GCC时遇到的依赖问题,也就是缺少GMPMPFRMPC这三个库的问题。用户提供的引用中有几个不同的解决方案,我需要先理解这些方法,然后整理出一个清晰的步骤。 首先,根据引用[4],用户可以使用GCC源码中的脚本`./contrib/download_prerequisites`来自动下载依赖包,这可能是一个比较简便的方法。不过用户可能不知道这个脚本的存在,或者可能遇到了脚本执行的问题。需要确认这个方法是否适用于所有GCC版本,或者是否有特定情况需要手动处理。 然后引用[2]和[3]提到了手动下载和安装这三个库的方法。手动安装需要用户分别下载各个库的源代码,然后依次安装,并指定安装路径,最后在配置GCC时通过`--with-gmp`、`--with-mpfr`、`--with-mpc`选项指定这些库的位置。这可能适用于那些需要自定义安装路径或者脚本自动下载失败的情况。 另外,引用[1]、[3]、[5]中提到了不同的配置选项,比如指定prefix路径,或者启用某些语言支持。需要注意这些选项的正确性,例如确保路径正确,库的版本符合要求。比如,GMP需要4.2+MPFR需要3.1.0+MPC需要0.8.0+。用户需要检查自己下载的版本是否符合要求,比如MPC0.9版本是否符合要求,或者是否需要更高的版本。 可能的步骤应该是首先尝试自动下载依赖,如果失败再手动安装。手动安装时需要注意安装顺序,因为MPFR依赖GMPMPC又依赖GMPMPFR,所以安装顺序应该是先GMP,再MPFR,最后MPC。每个库安装时需要指定前一个库的安装路径,这样才能正确链接。 另外,安装路径的问题也很重要。用户可能需要将库安装到系统默认路径,比如`/usr/local`,或者自定义路径。如果选择自定义路径,那么在配置GCC时需要正确指定这些路径,否则GCCconfigure脚本可能找不到这些库。 还需要考虑权限问题,使用sudo进行安装,或者将库安装到用户有权限的目录下。如果用户没有root权限,可能需要配置环境变量,如`LD_LIBRARY_PATH`,以便GCC在编译时能找到这些库。 用户的问题还可能涉及如何验证这些库是否安装成功,比如检查版本号,或者查看安装目录下的文件是否存在。另外,如果在配置GCC时仍然报错,可能需要检查路径是否正确,或者是否有其他依赖问题。 总结起来,解决方案应分为自动和手动两种方法。自动方法简单但可能不适用于所有情况,手动方法更可控但步骤较多。需要详细说明每一步的命令和注意事项,确保用户能够正确执行。此外,常见问题如路径错误、版本不匹配、依赖顺序等也需要在回答中提及,帮助用户避免这些陷阱。</think>### 解决GCC构建依赖问题的分步指南 在编译GCC时,若遇到缺少GMPMPFRMPC依赖的报错,可通过以下两种方法解决: --- #### **方法一:自动安装依赖(推荐)** 适用于GCC源码自带依赖管理脚本的情况: 1. 进入GCC源码根目录,执行自动下载依赖脚本: ```bash cd gcc-source-dir ./contrib/download_prerequisites ``` 该脚本会自动下载并解压GMPMPFRMPC、ISL等依赖库[^4]。 --- #### **方法二:手动安装依赖** 若自动脚本失效或需自定义路径,按顺序安装以下库: 1. **安装GMP** ```bash wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.bz2 tar -xvf gmp-6.2.1.tar.bz2 cd gmp-6.2.1 ./configure --prefix=/usr/local/gmp-6.2.1 make sudo make install ``` 2. **安装MPFR(依赖GMP)** ```bash wget https://www.mpfr.org/mpfr-current/mpfr-4.2.0.tar.gz tar -xvf mpfr-4.2.0.tar.gz cd mpfr-4.2.0 ./configure --prefix=/usr/local/mpfr-4.2.0 --with-gmp=/usr/local/gmp-6.2.1 make sudo make install ``` 3. **安装MPC(依赖GMPMPFR)** ```bash wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz tar -xvf mpc-1.3.1.tar.gz cd mpc-1.3.1 ./configure --prefix=/usr/local/mpc-1.3.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.2.0 make sudo make install ``` 4. **配置GCC时指定依赖路径** ```bash ../configure \ --prefix=/usr/local/gcc-xx.x.x \ --with-gmp=/usr/local/gmp-6.2.1 \ --with-mpfr=/usr/local/mpfr-4.2.0 \ --with-mpc=/usr/local/mpc-1.3.1 ``` 注意替换`gcc-xx.x.x`为实际GCC版本号[^2][^3]。 --- #### **验证安装** - 检查库版本是否符合要求: ```bash /usr/local/gmp-6.2.1/bin/gmp-config --version # GMP4.2 /usr/local/mpfr-4.2.0/bin/mpfr-config --version # MPFR3.1.0 /usr/local/mpc-1.3.1/bin/mpc-config --version # MPC0.8.0 ``` --- #### **常见问题** 1. **路径错误** 确保`--with-gmp`、`--with-mpfr`、`--with-mpc`指向实际安装路径,避免拼写错误。 2. **权限不足** 若未使用`sudo`安装依赖库,需将库路径加入环境变量: ```bash export LD_LIBRARY_PATH=/path/to/libs:$LD_LIBRARY_PATH ``` 3. **依赖顺序问题** 必须按GMPMPFRMPC顺序安装,后者依赖前者。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值