如何安装gmpy2错误:‘MPFR_RNDU’未声明(首次使用于该函数)

1 投票
1 回答
967 浏览
提问于 2025-04-20 05:20

我这样安装了gmpy2:

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

但是出现了这些错误:

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘real_round’

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘real_round’

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘imag_round’

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘underflow’

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘trap_underflow’

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘overflow’

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘trap_overflow’

src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘inexact’

 src/gmpy_mpc.c:1294: error: ‘gmpy_context’ has no member named ‘trap_inexact’

..........


src/gmpy2.c:969: error: ‘MPFR_RNDU’ undeclared (first use in this function)

src/gmpy2.c:970: error: ‘MPFR_RNDD’ undeclared (first use in this function)

src/gmpy2.c:971: error: ‘MPFR_RNDA’ undeclared (first use in this function)

error: command 'gcc' failed with exit status 1

到底哪里出问题了?我已经安装了gmp、mpfr、mpc,还有它们的开发版本,可是还是出现了这么多错误。为什么呢?

1 个回答

2

我是 gmpy2 的维护者。

gmpy2 需要比较新的 MPFR 和 MPC 版本。如果 setup.py 找不到合适的版本,它会显示以下警告信息:

----------------------------------------------------------------
setup.py was not able to detect the required versions of MPFR
and/or MPC. gmpy2 requires MPFR version 3.1.0 or greater and
MPC version 1.0.0 or greater. To specify a directory prefix that
contains the proper versions, use the --prefix=<dir> option.

In some circumstances, the correct versions may be present and
this warning can be ignored. If you have difficulties compiling
or running gmpy2, please try compiling with the --prefix option.

It is possible to compile gmpy2 without support for MPFR and MPC
but that is not a supported configuration. Beginning with v2.1.0,
MPFR and MPC will be required.

setup.py will continue and attempt to compile gmpy2.
-----------------------------------------------------------------

如果你无法安装最新版本的 GMP、MPFR 和 MPC,那么你需要自己编译这些库的版本,然后告诉 setup.py 使用你自己编译的版本。我通常会把我的版本安装到 /opt/local 目录下。以下说明假设源代码在 /opt/local/src,并且你使用的是有管理员权限的账户,可以使用 sudo

$ cd /opt/local/src/gmp-6.0.0
$ ./configure --prefix=/opt/local
$ make
$ make check
$ make install
$ cd /opt/local/src/mfr-3.1.2
$ ./configure --prefix=/opt/local --with-gmp=/opt/local
$ make
$ make check
$ make install
$ cd /opt/local/src/mpc-1.0.2
$ ./configure --prefix=/opt/local --with-gmp=/opt/local --with-mpfr=/opt/local
$ make
$ make check
$ make install
$ cd /opt/local/src/gmpy2-2.0.3
$ python setup.py build_ext --prefix=/opt/local
$ sudo python setup.py install

如果你需要在不同的系统上分发 gmpy2 库(比如实验室或计算机集群),可以编译一个静态链接的版本。如果你需要这些说明,随时告诉我。

撰写回答