1. 安装m4/g++
M4 是一个宏处理器,安装GMP依赖它。
执行命令
[root@VM-0-9-centos home]# yum install m4
另外g++也是需要的:
[root@VM-0-9-centos home]# yum install gcc-c++
2. 下载安装gmp
[root@VM-0-9-centos home]# mkdir gcc
[root@VM-0-9-centos home]# cd gcc
[root@VM-0-9-centos gcc]# wget https://gmplib.org/download/gmp/gmp-6.2.0.tar.xz
[root@VM-0-9-centos gcc]# tar -xvf gmp-6.2.0.tar.xz
[root@VM-0-9-centos gcc]# cd gmp-6.2.0
[root@VM-0-9-centos gmp-6.2.0]# ./configure –enable-cxx
[root@VM-0-9-centos gmp-6.2.0]# make
[root@VM-0-9-centos gmp-6.2.0]# make check
[root@VM-0-9-centos gmp-6.2.0]# make install
3. 测试
新建文件gmptest.cpp
, 如下
#include<iostream>
#include<gmpxx.h>
using namespace std;
int main()
{
mpz_class a;
a = 1;
for(int i = 0; i < 1000; i++)
a *= 2;
cout<<"2^1000 = "<<a<<endl;
//计算-12345*9876543210123456789
mpz_class b, c;
b = -12345;
c = "98765432100123456789";
cout<<"b * c = "<<b * c<<endl;
return 0;
}
执行命令编译
[root@VM-0-9-centos test]# g++ gmptest.cpp -lgmpxx -lgmp
执行后输出即配置成功
[root@VM-0-9-centos test]# ./a.out
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
b * c = -1219259259276024074060205
4. 参考
[1] https://blog.csdn.net/liufengl138/article/details/82805984
[2] https://blog.csdn.net/weixin_30248399/article/details/95712601
.
.
.
.
.
.
桃花仙人种桃树,又摘桃花换酒钱_