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.
How I built dynamic dll gmp-6.1.2 for windows so that the dll can be linked for a visual studio project.
Setup Environment
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64
lib
command. Your lib.exe
may be located elsewhere. Build GMP
bash.exe
from C:\cygwin64\bin
.cd "A:\Code\gmp-6.1.2"
./configure --disable-static --enable-shared
make
cyggmp-10.dll
under A:\Code\gmp-6.1.2\.libs\
make check
cd ./libs
lib /machine:i386 /def:cyggmp-10.dll
cyggmp-10.exp
and cyggmp-10.lib
under A:\Code\gmp-6.1.2\.libs\
for use with visual studioYou now have everything needed to call gmp from C# code.
For me, gmp was successfully built for x86, and I have had problems building x64. The problem was in the following:
In mpn\fib_table.c:
#if GMP_NUMB_BITS != 32
Error, error, this data is for 32 bits
#endif
while in 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.
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.
Tested on gmp 6.0.0.
See http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php , and note this paragraph;
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.
So you either disable assembly with ./configure --disable-assembly
or use MPIR.
You might want to take a look at MPIR. It is a fork of GMP that natively supports Visual Studio.
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