在 64 位 Windows 上构建 GMP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4711315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Build GMP on 64bit Windows
提问by franziga
I have followed the instruction on the "GMP Install Instruction for Windows Platform". I could build a 32bit version of GMP which can be used for Visual Studio.
我已按照“Windows 平台的 GMP 安装说明”中的说明进行操作。我可以构建可用于 Visual Studio 的 32 位版本的 GMP。
./configure --prefix=${gmp-install} --disable-static --enable-shared
make
make install
Then I installed mingw_w64 and msys on another machine (which is running 64bit Windows) and rerun the commands.
然后我在另一台机器(运行 64 位 Windows)上安装了 mingw_w64 和 msys 并重新运行命令。
./configure was run without any problem. However, when I run "make", I got the following.
./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
If I used "gmake" instead, the following error was shown.
如果我改用“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
I am not familiar with C++ make. Do I need to specify any flag in order to notify mingw_w64 that I am building for 64bit? Thanks.
我不熟悉 C++ make。我是否需要指定任何标志才能通知 mingw_w64 我正在为 64 位构建?谢谢。
采纳答案by franziga
I have tried the following. The library can be built successfully.
我尝试了以下方法。可以成功构建库。
./configure --prefix=/d/Temp/gmp-5.0.1-install --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-static --enable-shared
回答by capocannoniere
For me, gmp was successfully built for x86, and I have had problems building x64. The problem was in the following:
对我来说,gmp 是为 x86 成功构建的,而我在构建 x64 时遇到了问题。问题在于:
In mpn\fib_table.c:
在 mpn\fib_table.c 中:
#if GMP_NUMB_BITS != 32
Error, error, this data is for 32 bits
#endif
while in gmp.h:
在 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 is generated by gen-fix.exe tool, and this tool is generated by make.
fib_table.c由gen-fix.exe工具生成,本工具由make生成。
So, if one tries to build x64 build after building x86 (like me), it is not enough to run "make clean" first. Delete all "gen-*.exe" files in gmp root folder after running "make clean", this files will be rebuilt properly by make. gmp x64 was successfully build for me after that.
因此,如果有人在构建 x86 之后尝试构建 x64 构建(像我一样),首先运行“make clean”是不够的。运行“make clean”后删除gmp根目录下所有“gen-*.exe”文件,这些文件会被make正确重建。之后为我成功构建了 gmp x64。
Tested on gmp 6.0.0.
在 gmp 6.0.0 上测试。
回答by Derek Ziemba
How I built dynamic dll gmp-6.1.2 for windows so that the dll can be linked for a visual studio project.
我如何为 Windows 构建动态 dll gmp-6.1.2,以便可以将 dll 链接到 Visual Studio 项目。
Setup Environment
设置环境
- Install 7-Zip
- Install Cygwin, add the following packages to the default installation
- gcc-core
- gcc-g++
- libgcc
- m4
- make
- cmake
- bash
- Add the following Environment Variable to the User PATH:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64
- This is so you can use the
lib
command. Yourlib.exe
may be located elsewhere.
- This is so you can use the
- 安装 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
可能位于其他地方。
- 这样您就可以使用该
Build GMP
建立GMP
- Download the tar.bz2 version from https://gmplib.org/#DOWNLOADand extract the gmp-6.1.2 folder with 7-zip.
- Launch
bash.exe
fromC:\cygwin64\bin
. - Change directory to the unzipped gmp-6.1.2 folder. Ex:
cd "A:\Code\gmp-6.1.2"
- Execute
./configure --disable-static --enable-shared
- Execute
make
- This will create
cyggmp-10.dll
underA:\Code\gmp-6.1.2\.libs\
- This will create
- Execute
make check
- Execute
cd ./libs
- Execute
lib /machine:i386 /def:cyggmp-10.dll
- This will generate
cyggmp-10.exp
andcyggmp-10.lib
underA:\Code\gmp-6.1.2\.libs\
for use with visual studio
- This will generate
- 从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.lib
下A:\Code\gmp-6.1.2\.libs\
了与Visual Studio使用
- 这将生成
You now have everything needed to call gmp from C# code.
您现在拥有从 C# 代码调用 gmp 所需的一切。
回答by ismail
See http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php, and note this paragraph;
参见http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php,并注意这一段;
GMP cannot, however, provide high performance 64-bit libraries on Windows because its 64-bit assembler code is incompatible with Windows x64 calling conventions. This means that 64-bit GMP libraries on WIndows are very slow when compared with MPIR, which has excellent 64-bit assembler support.
但是,GMP 不能在 Windows 上提供高性能的 64 位库,因为它的 64 位汇编代码与 Windows x64 调用约定不兼容。这意味着与具有出色的 64 位汇编程序支持的 MPIR 相比,Windows 上的 64 位 GMP 库非常慢。
So you either disable assembly with ./configure --disable-assembly
or use MPIR.