构建GCC需要GMP 4.2+,MPFR 2.3.1+和MPC 0.8.0+。

109

我从http://www.netgull.com/gcc/releases/gcc-4.5.0/下载了GCC 4.5,但在尝试设置/构建时出现以下错误:

Linux:>~/shared_scripts/bin/gcc/gcc-4.5.0 1040> /x/home/prakash_satya/shared_scripts/bin/gcc/gcc-4.5.0/configure CC="gcc -m64" --prefix=/x/home/prakash_satya/shared_scripts/bin/gcc/gcc-4.5.0 --with-gmp-lib=/usr/lib64 --with-mpfr-lib=/usr/lib64 --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-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... /bin/sed
checking for gawk... gawk
checking for gcc... gcc -m64
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -m64 accepts -g... yes
checking for gcc -m64 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 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... 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.
Linux:>~/shared_scripts/bin/gcc/gcc-4.5.0 1041>
以下库存在各自的目录中。
/usr/lib/libgmp.a
/usr/lib64/libgmp.a

/usr/lib/libmpfr.a
/usr/lib64/libmpfr.a

我的机器上没有安装libmpc.a库。

基于这个错误信息,我如何知道:

a) 当前安装的libgmp.a和libmpfr.a版本是什么。

b) 如果它们的版本不正确,我如何部署我的自定义版本而不影响当前版本?


63
尝试在gcc源代码目录中运行 ./contrib/download_prerequisites.sh。这对我有用(不过仅适用于当前版本的gcc (gcc-4.7))。 - Sebastian
29
脚本似乎不再具有.sh扩展名:./contrib/download_prerequisites - Jeroen Ooms
download_prerequisites.sh是在4.6版本中添加的。看起来4.5.0没有它。 - bobpaul
./contrib/download_prerequisites 也适用于gcc-4.8.5。谢谢。 - undefined
6个回答

263

在gcc目录中执行以下命令:

./contrib/download_prerequisites

在运行该脚本后,GMP、MPFR和MPC将准备就绪。然后继续执行./configure命令。


2
我正在尝试在Windows上的Ubuntu Bash中安装gcc 6.2,这个命令对我有用。谢谢! - Emile Vrijdags
3
谢谢。我被卡在一台没有sudo权限的机器上,这个方法解决了我的烦恼。 - Arnon
2
我一整天都在找这个,非常感谢! - Stephen C
4
你是我的英雄。 - Daniel Brooks
7
没错,这应该是正确的答案。超级棒。 - evensis
显示剩余5条评论

73

我曾经尝试安装/编译GCC 4.8.1时遇到了同样的问题。这是我解决的方法:

在Debian中,只需运行这两个命令:

apt-get install libmpc-dev
./configure

2
在Amazon Linux上,可以使用sudo yum install libmpc-devel命令进行安装。 - Jonathon Hill
1
Centos还需要sudo yum install libmpc-devel - bebbo
在Ubuntu 16上,可以使用sudo apt-get install libmpc-dev进行安装。 - user3788941
在Raspbian 9.13上,没有libmpc-dev这样的东西。 - Nathan B

25

我遇到了编译GCC 4.9分支的相同问题。

对于基于Red HatFedora的系统,请运行以下命令:

sudo yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel

这将安装GNU多精度(MP)库,用于整数、浮点数和复数。


12
在我安装了这些库的目录下(/usr/gnu64/lib),我还有一个libgmp.la文件(以及libmpc.lalibmpfr.la文件),它们包含可读的文本。SO版本信息在其中,但并不完全等同于“产品版本”。它是关于链接兼容性的信息。
我试图调查我安装的是哪个版本,而我想到的奇怪解决方案是使用带有-v选项构建的GCC(4.6.1)运行。部分内容如下:
GNU C (GCC) version 4.6.1 (x86_64-apple-darwin11.1.0)
    compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 3.0.0, MPC version 0.8.2
warning: GMP header version 5.0.1 differs from library version 5.0.2.
warning: MPFR header version 3.0.0 differs from library version 3.1.0.
warning: MPC header version 0.8.2 differs from library version 0.9.

看起来我安装了GMP 5.0.2(但我使用的是GCC 5.0.1构建),以及MPFR 3.1.0(但我使用的是GCC 3.0.0构建)和MPC 0.9(但我使用的是GCC 0.8.2构建)。这种不匹配的情况是因为我尝试编译并安装GCC 4.6.2,它可能需要更新的版本。(我没有成功,但那是另一回事。)

我将自定义构建的库安装在/usr/gnu64/lib中,并使用配置选项--with-mpfr=/usr/gnu64/lib--with-gmp=/usr/gnu64/lib--with-mpc=/usr/gnu/64/lib告诉GCC这就是它们的位置。这些路径已经硬编码到GCC中,从那里工作。


我尝试了相同的步骤,使用--with-gmp/mpfr将.a和.la复制到本地文件夹,但仍然出现相同的错误。此外,我从ftp://gcc.gnu.org/pub/gcc/infrastructure/ [gmp-4.3.2.tar.bz2, mpfr-2.4.2.tar.bz2, mpc-0.8.1.tar.gz]下载并构建了gmp/mpfr/mpc,但构建mpc时出现错误 - configure: error: GMP version >= 4.2 required,而gcc仍然显示相同的错误。 - Programmer
@Prakash:在这种情况下,假设GCC及其配置套件知道自己在做什么,并开始编译和安装其他三个库。我总是将其作为单独的操作完成,而不参考GCC(即使GCC触发了重建)。我相信有一种方法可以让GCC在构建和安装库时进行 - 通过在GCC源树中拥有GMP、MPFR、MPC的源代码。请查看“./configure --help”输出以获取信息。 - Jonathan Leffler
2
自从写了这篇文章以后,我开始让GCC与编译器一起构建GMP、MPFR和MPC的版本。现在我获取当前版本库的源代码,并将其提取到GCC源代码的顶层目录中:gmp-6.0.0、mpfr-3.1.2等。然后我为每个库创建一个符号链接:ln -s gmp-6.0.0 gmp; ln -s mpfr-3.1.2 mpfr; ln -s mpc-1.0.2 mpc。然后我运行GCC配置和构建,GCC也会构建这些库。 - Jonathan Leffler

1

Centos7: sudo yum install libmpc-devel


1
感谢您提供答案。顺便说一下,与其仅仅给出答案,告诉其他人为什么要运行该命令以及它应该做什么会更有帮助。此外,确保回答所问的所有问题也是一个好主意。 - Josh

0

我已经在contrib/download_prerequisites中更改了base_url为base_url='gcc.gnu.org/pub/gcc/infrastructure/'。然后只需按照gcc网站上的步骤进行即可。这个方法非常有效。希望能对你有所帮助。


你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心找到有关如何编写良好答案的更多信息。 - Community
其他评论更好地回答了这个问题。你的回答应该被删除。 - LUser

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接