## 1 介绍

• 首先查看一下MPFR库到底是什么样的C语言库，下面是它的官网给出简介，可以知道MPFR是一个基于GMP库的高精度浮点计算库。

The MPFR library is a C library for multiple-precision floating-point computations with correct rounding. MPFR has continuously been supported by the INRIA and the current main authors come from the Caramba and AriC project-teams at Loria (Nancy, France) and LIP (Lyon, France) respectively; see more on the credit page. MPFR is based on theGMP multiple-precision library.

The main goal of MPFR is to provide a library for multiple-precision floating-point computation which is both efficient and has a well-defined semantics. It copies the good ideas from the ANSI/IEEE-754 standard for double-precision floating-point arithmetic (53-bit significand).

• GMP的官网对它有下面的介绍，它用于任意精度算术，对有符号整数，有理数和浮点数进行操作。

GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on. GMP has a rich set of functions, and the functions have a regular interface.

• 所以需要先编译GMP，然后再编译MPFR才可以。本文使用的系统是64位的Ubuntu 16.04，GMP版本是6.1.2， MPFR版本是4.0.2

## 3 MPFR的编译

• 同GMP的类似，运行的4条命令进行MPFR的编译和安装。

./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib

make

make check （这里产生少量报错的话可以忽视）

make install

• 最后结束时打开/usr/local/include/usr/local/lib文件夹可以看到又发生了下面的变化。

## 4 测试并解决BUG

• 这里使用MPFR官方给出的案例代码来进行测试，它们可以在解压缩包里的examples文件夹找到，本文选择了version.c文件进行测试。

不幸的是，当运行生成文件查看结果时却得到了报错，信息如下。

libmpfr.so.6: cannot open shared object file

说明64位Ubuntu运行32位应用libmpfr.so.6无法被链接到。

• 解决方案：

• 首先安装一些必要的东西。

• 接下来做文件间的链接，因为MPFR依赖于GMP，所以要进行两次。

• 接下来重新查看结果，发现问题得到了解决，输出如下。

------------- 本文结束 感谢您的阅读 -------------

0%