分页: 1 / 1
MinGW编译GMP库以及示例代码
发表于 : 2016年10月09日 03:01
由 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
无误。
具体使用方法请查阅官方手册,示例代码和编译指令请看二楼
华丽的分割线
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月09日 09:18
由 happy886rr
自己编译的GMP大数库4.1、5.9、6.1三合一版
示例用法
/*计算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;
}
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月09日 09:29
由 523066680
happy886rr 写了:自己编译的GMP大数库4.1、5.9、6.1三合一版
求库的编译方法(莫非应该用cygwin?)
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月09日 09:55
由 happy886rr
5月份,那会编译的,就是win7直接就能编译啊。没啥阻碍msys下一次就过。莫非你是xp
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月09日 10:15
由 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
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月09日 10:20
由 happy886rr
我都是32位win7编译,GMP还算好编译。有个矩阵库,我编译了3天都没过,后来发现,编译那个矩阵库需要先编译GMP以及其他数个库。你检查下兼容性。
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月09日 12:47
由 523066680
happy886rr 写了: mpz_ui_pow_ui(t,2,10000000); //GMP所有函数基本都是以mpz打头
纠正,应该:mpz是整数 mpf是浮点数 mpr是有理数
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月12日 11:53
由 灵台方寸山
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;
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年10月12日 11:56
由 灵台方寸山
Re: MinGW编译GMP库以及示例代码
发表于 : 2016年11月26日 10:13
由 happy886rr
哈哈,gmp.dll我都是直接偷mathmatica的用,那可是最优化的gmp。计算斐波那契数列5亿项都是十多秒就出来了。