在64位Windows上构建GMP

19

我已经按照"Windows平台下的GMP安装指令"进行了操作。 我可以构建一个32位版本的GMP,可用于Visual Studio。

./configure --prefix=${gmp-install} --disable-static --enable-shared
make
make install

然后我在另一台运行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

如果我使用"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

我不熟悉C++的make。我需要指定任何标志来通知mingw_w64,我正在构建64位吗?谢谢。

5个回答

13

对我来说,GMP在x86上已经成功构建,但在构建x64时遇到了问题。问题出在以下代码中:

在mpn\fib_table.c文件中:

#if GMP_NUMB_BITS != 32
Error, error, this data is for 32 bits
#endif

在 gmp.h 中:

#define GMP_LIMB_BITS                      64
#define GMP_NAIL_BITS                      0
#define GMP_NUMB_BITS     (GMP_LIMB_BITS - GMP_NAIL_BITS)

fib_table.c是由gen-fix.exe工具生成的,而此工具是由make生成的。

因此,如果在构建x86后尝试构建x64(就像我一样),仅运行“make clean”是不够的。在运行“make clean”后删除gmp根文件夹中的所有“gen-*.exe”文件,这些文件将被make正确重建。在此之后,我成功地为gmp x64构建了。

在gmp 6.0.0上测试过。


即使使用新的 clone./.bootstrap,目前我只能构建出 libgmp.a 的 x86_64 版本。 - vesperto
gmp-6.2.1.tzx 相同(因为 SO 的 5 分钟规则而添加的额外注释)。 - vesperto

11
  • 这是为了将动态链接库与Visual Studio项目链接而构建动态dll gmp-6.1.2的步骤。
  • 设置环境

    • 安装7-Zip
    • 安装Cygwin,并添加以下软件包到默认安装:
      • gcc-core
      • gcc-g++
      • libgcc
      • m4
      • make
      • cmake
      • bash
    • 将以下环境变量添加到用户PATH中: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文件夹。
    • C:\cygwin64\bin启动bash.exe
    • 更改目录到解压缩的gmp-6.1.2文件夹。例如:cd "A:\Code\gmp-6.1.2"
    • 执行./configure --disable-static --enable-shared
    • 执行make
      • 这将在A:\Code\gmp-6.1.2\.libs\下创建cyggmp-10.dll
    • 执行make check
    • 执行cd ./libs
    • 执行lib /machine:i386 /def:cyggmp-10.dll
      • 这将生成cyggmp-10.expcyggmp-10.lib,放置在A:\Code\gmp-6.1.2\.libs\ 目录下,可与Visual Studio一起使用。

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


    你好,最后一步的lib命令是什么意思?我的Bash认为它是一个系统命令。 - Laser Infinite

    9
    请参考http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php,注意以下内容:
    然而,GMP无法在Windows上提供高性能的64位库,因为其64位汇编代码与Windows x64调用约定不兼容。这意味着与具有出色的64位汇编支持的MPIR相比,Windows上的64位GMP库非常慢。
    因此,您可以使用./configure --disable-assembly禁用汇编,或者使用MPIR

    10
    GMP 5.1.0 开始,“在 M$ Windows 的 64 位 ABI 下的性能得到了极大的改善,这要归功于完整的汇编支持。”(具体有多大改善不得而知。) - Will Daniels

    7

    您可能想了解一下MPIR。它是GMP的一个分支,原生支持Visual Studio。


    6
    我尝试过以下步骤。该库已经成功构建。
    ./configure --prefix=/d/Temp/gmp-5.0.1-install --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-static --enable-shared
    

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接