在64位Windows上构建GMP

问题描述 投票:9回答:5

我遵循了"GMP Install Instruction for Windows Platform"上的指示。我可以构建一个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位构建?谢谢。

windows build 64-bit mingw gmp
5个回答
8
投票

对我来说,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上测试过。


4
投票

http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php,并注意本段;

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

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


4
投票

我尝试了以下内容。该库可以成功构建。

./configure --prefix=/d/Temp/gmp-5.0.1-install --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-static --enable-shared

3
投票

我如何为windows构建动态dll gmp-6.1.2,以便可以为可视工作室项目链接dll。

设置环境

  • 安装7-Zip
  • 安装Cygwin,将以下软件包添加到默认安装中 GCC核心 GCC-克++ libgcc中 M4 使 cmake的 庆典
  • 将以下环境变量添加到用户路径: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.exe发射C:\cygwin64\bin
  • 将目录更改为解压缩的gmp-6.1.2文件夹。例如:cd "A:\Code\gmp-6.1.2"
  • 执行./configure --disable-static --enable-shared
  • 执行make 这将在cyggmp-10.dll下创建A:\Code\gmp-6.1.2\.libs\
  • 执行make check
  • 执行cd ./libs
  • 执行lib /machine:i386 /def:cyggmp-10.dll 这将在cyggmp-10.exp下生成cyggmp-10.libA:\Code\gmp-6.1.2\.libs\,用于视觉工作室

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


1
投票

你可能想看看MPIR。它是GMP的一个分支,本身支持Visual Studio。

© www.soinside.com 2019 - 2024. All rights reserved.