mpc库问题导致gcc编译失败
使用 mpc-1.3.0 编译 gcc-13.1.0,执行 gcc 的 configure 时遇到如下错误:
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+.
检查 mpc 版本:
# Check for the MPC header version.
if test "x$require_mpc" = xyes && test x"$have_gmp" = xyes ; then
# Check for the recommended and required versions of MPC.
AC_MSG_CHECKING([for the correct version of mpc.h])
AC_TRY_COMPILE([#include <mpc.h>],[
#if MPC_VERSION < MPC_VERSION_NUM(0,8,0)
choke me
#endif
], [AC_TRY_COMPILE([#include <mpc.h>],[
#if MPC_VERSION < MPC_VERSION_NUM(0,8,1)
choke me
#endif
], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([buggy but acceptable])])],
[AC_MSG_RESULT([no]); have_gmp=no])
fi
# cat x.cpp
#include <stdio.h>
#include <mpc.h>
int main() {
printf("MPC_VERSION:%d\n", MPC_VERSION);
printf("MPC_VERSION_NUM(0,8,0): %d\n", MPC_VERSION_NUM(0,8,0));
return 0;
}
# g++ -g -o x x.cpp -I/usr/local/mpc/include -I/usr/local/gmp/include -I/usr/local/mpfr/include
# ./x
MPC_VERSION:66304
MPC_VERSION_NUM(0,8,0): 2048
# Check for the MPC header version.
if test "x$require_mpc" = xyes && test x"$have_gmp" = xyes ; then
# Check for the recommended and required versions of MPC.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the correct version of mpc.h" >&5
$as_echo_n "checking for the correct version of mpc.h... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <mpc.h>
int
main ()
{
#if MPC_VERSION < MPC_VERSION_NUM(0,8,0)
choke me
#endif
;
return 0;
}
_ACEOF
在 config.log 找到的错误信息:
configure:8174: checking for the correct version of mpc.h
configure:8191: gcc -std=gnu99 -c -g -O2 -I/usr/local/gmp/include -I/usr/local/mpfr/include -I/usr/local/mpc/include conftest.c >&5
In file included from conftest.c:10:0:
/usr/local/mpc/include/mpc.h:287:35: error: unknown type name 'FILE'
__MPC_DECLSPEC void mpcr_out_str (FILE *f, mpcr_srcptr r);
^
configure:8191: $? = 1
打开 mpc.h,可以看到:
#include <stdint.h>
#include "gmp.h"
#include "mpfr.h"
这里没有 include 头文件 stdio.h,导致错误”unknown type name 'FILE'“,加上后即可消除错误:
#include <stdint.h>
#include <stdio.h>
#include "gmp.h"
#include "mpfr.h"
mpc 源代码仓库:
(https://gitlab.inria.fr/mpc/mpc)[https://gitlab.inria.fr/mpc/mpc]
解决办法,修改文件 mpc.h,添加“#include <stdio.h>”:
sed -i '/#include <stdint.h>/a\#include <stdio.h>' /usr/local/mpc/include/mpc.h