在64位Windows上构建GMP

fra*_*iga 10 windows 64-bit mingw build gmp

我已按照"Windows平台的GMP安装说明"中的说明进行操作.我可以构建一个32位版本的GMP,可以用于Visual Studio.

./configure --prefix=${gmp-install} --disable-static --enable-shared
make
make install
Run Code Online (Sandbox Code Playgroud)

然后我在另一台机器(运行64位Windows)上安装了mingw_w64和msys并重新运行命令.

./configure运行没有任何问题.但是,当我运行"make"时,我得到了以下内容.

m4  -DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -DOPERATION_add_n -DDLL_EXPORT -DPIC add_n.asm >tmp-add_n.s
gcc -std=gnu99 -c -DHAVE_CONFIG_H -I. -I.. -D__GMP_WITHIN_GMP -I.. -DOPERATION_add_n -O2 -pedantic -fomit-frame-pointer -mno-cygwin tmp-add_n.s -DDLL_EXPORT -DPIC -o .libs/add_n.o
tmp-add_n.s: Assembler messages:
tmp-add_n.s:84: Error: operand type mismatch for `push'
tmp-add_n.s:85: Error: operand type mismatch for `push'
tmp-add_n.s:86: Error: operand type mismatch for `push'
tmp-add_n.s:107: Error: operand type mismatch for `jmp'
tmp-add_n.s:114: Error: operand type mismatch for `pop'
tmp-add_n.s:115: Error: operand type mismatch for `pop'
tmp-add_n.s:116: Error: operand type mismatch for `pop'
make[2]: *** [add_n.lo] Error 1
make[2]: Leaving directory `/d/Temp/gmp-5.0.1/mpn'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/d/Temp/gmp-5.0.1'
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)

如果我使用"gmake"代替,则显示以下错误.

m4 gcc  -DHAVE_CONFIG_H -D__GMP_WITHIN_GMP -DOPERATION_add_n -DDLL_EXPORT -DPIC add_n.asm >tmp-add_n.s
m4: gcc: No such file or directory
gmake[2]: *** [add_n.lo] Error 1
gmake[2]: Leaving directory `d:/Temp/gmp-5.0.1/mpn'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `d:/Temp/gmp-5.0.1'
gmake: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)

我不熟悉C++ make.我是否需要指定任何标志才能通知mingw_w64我正在为64位构建?谢谢.

Der*_*mba 11

我如何为 Windows 构建动态 dll gmp-6.1.2,以便可以将 dll 链接到 Visual Studio 项目。

设置环境

  • 安装 7-Zip
  • 安装Cygwin,默认安装添加以下包
    • gcc核心
    • gcc-g++
    • 米4
    • 制作
    • 制作
    • 猛击
  • 将以下环境变量添加到用户路径: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64
    • 这样您就可以使用该lib命令。您lib.exe可能位于其他地方。

建立GMP

  • https://gmplib.org/#DOWNLOAD下载 tar.bz2 版本并用 7-zip 解压 gmp-6.1.2 文件夹。
  • 启动bash.exeC:\cygwin64\bin
  • 将目录更改为解压缩的 gmp-6.1.2 文件夹。前任:cd "A:\Code\gmp-6.1.2"
  • 执行 ./configure --disable-static --enable-shared
  • 执行 make
    • 这将创建cyggmp-10.dllA:\Code\gmp-6.1.2\.libs\
  • 执行 make check
  • 执行 cd ./libs
  • 执行 lib /machine:i386 /def:cyggmp-10.dll
    • 这将生成cyggmp-10.expcyggmp-10.libA:\Code\gmp-6.1.2\.libs\了与Visual Studio使用

您现在拥有从 C# 代码调用 gmp 所需的一切。


ism*_*ail 8

参见http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php,并注意这一段;

但是,GMP 不能在 Windows 上提供高性能的 64 位库,因为它的 64 位汇编代码与 Windows x64 调用约定不兼容。这意味着与具有出色 64 位汇编程序支持的 MPIR 相比,Windows 上的 64 位 GMP 库非常慢。

因此,您要么./configure --disable-assembly使用MPIR禁用程序集,要么使用MPIR

  • NB:自从[GMP 5.1.0](http://gmplib.org/list-archives/gmp-announce/2012-December/000036.html)“M$ Windows 64位ABI下的性能有了很大的提升感谢完整的组装支持。” (多少所以我不知道)。 (8认同)

小智 8

对我来说,gmp是为x86成功构建的,我在构建x64时遇到了问题.问题在于:

在mpn\fib_table.c中:

#if GMP_NUMB_BITS != 32
Error, error, this data is for 32 bits
#endif
Run Code Online (Sandbox Code Playgroud)

在gmp.h中:

#define GMP_LIMB_BITS                      64
#define GMP_NAIL_BITS                      0
#define GMP_NUMB_BITS     (GMP_LIMB_BITS - GMP_NAIL_BITS)
Run Code Online (Sandbox Code Playgroud)

fib_table.c由gen-fix.exe工具生成,该工具由make生成.

因此,如果在构建x86之后尝试构建x64构建(像我一样),那么首先运行"make clean"是不够的.运行"make clean"后,删除gmp根文件夹中的所有"gen - *.exe"文件,make文件将正确重建.之后gmp x64为我成功构建.

在gmp 6.0.0上测试过.


cas*_*evh 6

您可能想看看MPIR。它是原生支持 Visual Studio 的 GMP 的一个分支。


fra*_*iga 6

我尝试了以下方法。可以成功构建库。

./configure --prefix=/d/Temp/gmp-5.0.1-install --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-static --enable-shared
Run Code Online (Sandbox Code Playgroud)