MinGW编译GMP库以及示例代码

回复
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

MinGW编译GMP库以及示例代码

帖子 523066680 »

GMP - The GNU Multiple Precision Arithmetic Library
高精度运算库

测试环境
WIN7 64bit + MinGW + MSYS2.0

官网:https://gmplib.org/
版本资源列表: https://gmplib.org/download/gmp/

如果懒得折腾,可以下载编译好的(版本比较旧):
http://cs.nyu.edu/exact/core/gmp/
或者
https://sourceforge.net/projects/gmpmingw
gmp-5.0.2-mingw32.zip

编译:
gmp-6.1.1.tar.bz2为例,解压,打开 MinGW-w64 Win32 Shell 进入目录
执行 ./configure
$ ./configure
Version: GNU MP 6.1.0 Host type: core2-pc-mingw32 ABI: 64 Install prefix: /usr/local Compiler: gcc Static libraries: yes Shared libraries: no
执行make
$ make
libtool: compile: ../mpn/m4-ccas "--m4=m4 gcc" -c -DHAVE_CONFIG_H -I. -I.. -D__GMP_WITHIN_GMP -I.. -DOPERATION_invert_limb_table -O2 -pedantic -fomit-frame-pointer -m64 -mtune=core2 -march=core2 invert_limb_table.asm -o invert_limb_table.o m4 gcc -DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -DOPERATION_invert_limb_table invert_limb_table.asm >tmp-invert_limb_table.s m4: cannot open `gcc': No such file or directory make[2]: *** [Makefile:768: invert_limb_table.lo] Error 1 make[2]: Leaving directory 'D:/gmp-6.1.1/mpn' make[1]: *** [Makefile:955: all-recursive] Error 1 make[1]: Leaving directory 'D:/gmp-6.1.1' make: *** [Makefile:774: all] Error 2
出错,提示找不到gcc

解决方法:
http://www.cplusplus.com/forum/lounge/114348/
http://mingw.5.n7.nabble.com/help-to-co ... 12597.html
找到 \mpn\Makefile,编辑,找到文件末尾的 "$(M4)" 并将双引号去除,保存。再次make,无误。

make check
$ make check
============================================================================ Testsuite summary for GNU MP 6.1.1 ============================================================================ # TOTAL: 15 # PASS: 15 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0
无误。

具体使用方法请查阅官方手册,示例代码和编译指令请看二楼

华丽的分割线
happy886rr
渐入佳境
渐入佳境
帖子: 45
注册时间: 2016年09月27日 16:11
联系:

Re: MinGW编译GMP库以及示例代码

帖子 happy886rr »

自己编译的GMP大数库4.1、5.9、6.1三合一版
GMP大数运算库(3合1).7z
GMP库
(697.33 KiB) 已下载 57 次
示例用法
/*计算2的一千万次方
gcc下编译命令 gcc test.c -lgmp -L./GMP
*/
#include "gmp.h"

int main(int argc, char* argv[])
{
mpz_t t; //mpz_t 为GMP内置大数类型
mpz_init(t); //大数t使用前要进行初始化,以便动态分配空间
mpz_ui_pow_ui(t,2,10000000); //GMP所有函数基本都是以mpz打头
gmp_printf("2^100=%Zd\n",t); //输出大数,大数的格式化标志为%Zd
mpz_clear(t);
return 0;
}
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Re: MinGW编译GMP库以及示例代码

帖子 523066680 »

happy886rr 写了:自己编译的GMP大数库4.1、5.9、6.1三合一版
求库的编译方法(莫非应该用cygwin?)
happy886rr
渐入佳境
渐入佳境
帖子: 45
注册时间: 2016年09月27日 16:11
联系:

Re: MinGW编译GMP库以及示例代码

帖子 happy886rr »

5月份,那会编译的,就是win7直接就能编译啊。没啥阻碍msys下一次就过。莫非你是xp
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Re: MinGW编译GMP库以及示例代码

帖子 523066680 »

happy886rr 写了:5月份,那会编译的,就是win7直接就能编译啊。没啥阻碍msys下一次就过。莫非你是xp
win7 64
gcc (GCC) 6.1.0
msys2.0 32和64的shell都试过了

不知道为啥这么曲折,我懵了,待会换台电脑试试 =_=

./configure
Version:           GNU MP 6.1.0
Host type: core2-pc-mingw32
ABI: 64
Install prefix: /usr/local
Compiler: gcc
Static libraries: yes
Shared libraries: no
happy886rr
渐入佳境
渐入佳境
帖子: 45
注册时间: 2016年09月27日 16:11
联系:

Re: MinGW编译GMP库以及示例代码

帖子 happy886rr »

我都是32位win7编译,GMP还算好编译。有个矩阵库,我编译了3天都没过,后来发现,编译那个矩阵库需要先编译GMP以及其他数个库。你检查下兼容性。
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Re: MinGW编译GMP库以及示例代码

帖子 523066680 »

happy886rr 写了: mpz_ui_pow_ui(t,2,10000000); //GMP所有函数基本都是以mpz打头
纠正,应该:mpz是整数 mpf是浮点数 mpr是有理数
头像
灵台方寸山
出类拔萃
出类拔萃
帖子: 76
注册时间: 2016年08月06日 16:40
来自: [color=red]斜月三星洞[/color]

Re: MinGW编译GMP库以及示例代码

帖子 灵台方寸山 »

In this manual, integer usually means a multiple precision integer, as defined by the GMP library. The C data type for such integers is mpz_t. Here are some examples of how to declare such integers:

mpz_t sum;

struct foo { mpz_t x, y; };

mpz_t vec[20];
Rational number means a multiple precision fraction. The C data type for these fractions is mpq_t. For example:

mpq_t quotient;
Floating point number or Float for short, is an arbitrary precision mantissa with a limited precision exponent. The C data type for such objects is mpf_t. For example:

mpf_t fp;
:crazylaugh3 :oh_no
少发点科普,对中医产业,骗子产业不好。
头像
灵台方寸山
出类拔萃
出类拔萃
帖子: 76
注册时间: 2016年08月06日 16:40
来自: [color=red]斜月三星洞[/color]

Re: MinGW编译GMP库以及示例代码

帖子 灵台方寸山 »

:crazylaugh4
玩nim调下了gmp,运行提示不能load libgmp.dll,一搜索,发现julia目录下有这个DLL,复制过就好了。。

:coverface1


:jiong1
:crazylaugh3 :oh_no
少发点科普,对中医产业,骗子产业不好。
happy886rr
渐入佳境
渐入佳境
帖子: 45
注册时间: 2016年09月27日 16:11
联系:

Re: MinGW编译GMP库以及示例代码

帖子 happy886rr »

哈哈,gmp.dll我都是直接偷mathmatica的用,那可是最优化的gmp。计算斐波那契数列5亿项都是十多秒就出来了。
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 2 访客