mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2021-09-18, 06:32   #1
moytrage
 
Jul 2021

418 Posts
Default GMP for Windows (MSVC)?

Can anyone suggest steps how to compile GMP for Windows? I need to use it under MSVC. Also I need it as a static library without any DLL dependencies.

Some people post instructions how to build it using Cygwin. But Cygwin always dynamically links Cygwin's system dlls. And I need fully static solution, so that my final EXE has no DLL deps. Also I'm not very sure if Cygwin version of GMP will be friendly to use in MSVC.

Maybe MSYS has ability to build such dependencies free static library? Does anyone know how can I use such msys-generated library in MSVC without problems?

Also I'm aware that there exists MPIR library, which should be more Windows-friendly. But right now I need specifically GMP solution.

Also if possible to build GMP for MSVC usage then of course would be preferrable to do all optimizations including all assembly code. If not possible to use assembly in Windows then if someone can suggest steps how to compile for MSVC but without assembly?

I'm alright with building GMP not in MSVC, but in Cygwin or MSYS as far as it can be used later in MSVC without any problems. And as I told only statical solution is acceptable for me, without any DLL dependencies.
moytrage is offline   Reply With Quote
Old 2021-09-18, 16:26   #2
Prime95
P90 years forever!
 
Prime95's Avatar
 
Aug 2002
Yeehaw, FL

5×29×53 Posts
Default

I think you are stuck with MSYS (if you get MSVC to build it, do post instructions on how to do it!).
Here are my many-years-old build notes for building on MSYS. Note the use of MSVC library tools.
If you flip the disable-static and enable-shared options maybe these instructions will serve your needs.


Code:
Building libgmp-10.dll  (rename this DLL to something unique.  Ordinals can change with each source change.  DLL hell)
----------------------

Install msys2 from msys2.org  (see http://repo.msys2.org/distrib/i686/ for the October 2016 installer)
pacman -Syuu	(exit and repeat)
pacman -S tar
pacman -S gcc			(not needed?)
pacman -S m4
pacman -S make
pacman -S diffutils
pacman -S libtool
pacman -S mingw-w64-i686-gcc
pacman -S mingw-w64-x86_64-gcc
download gmp sources (the .bz2 file, not the .lz file)
Close the MSYS shell

Launch mingw32 shell:
tar xvf gmp sources
./configure --prefix=/home/gmp_dir --enable-fat --disable-static --enable-shared  
	(note:  may be best if gmpdir does not contain any spaces, though I got away with single-quoting)
make
make check
From Windows shell:
run vcvars (see c.bat)
cd .libs
rename libgmp-10.dll libgmp-gw1.dll
rename libgmp-3.dll.def libgmp-gw1.def
lib /def:libgmp-gw1.def /out:libgmp-gw1.lib

Launch mingw64 shell:				(built on 64-bit Windows machine!)
tar xvf gmp sources
./configure --prefix=/home/gmp_dir64 --enable-fat --disable-static --enable-shared  
make
make check
From Windows shell:
run vcvars (see c64.bat)
cd .libs 
rename libgmp-10.dll libgmp-gw1.dll
rename libgmp-3.dll.def libgmp-gw1.def
lib /def:libgmp-gw1.def /out:libgmp-gw1.lib /MACHINE:X64
Prime95 is online now   Reply With Quote
Old 2021-09-18, 17:24   #3
moytrage
 
Jul 2021

3310 Posts
Default

Quote:
Originally Posted by Prime95 View Post
if you get MSVC to build it, do post instructions on how to do it!
Right now I successfully managed to build my medium-sized GMP-based program in MSVC, that does Pollard-Rho factoring, using several C operations from gmp.h (mpz_... functions) and many operations from gmpxx.h (mpz_class C++ objects).

I used .a prebuilt libraries taken from MSYS distribution.

Besides regular process of compiling through MSVC, I did extra following things:

1) Installed GMP in MSYS through "pacman -S mingw-w64-clang-x86_64-gmp"

2) Added to MSVC include search path (/I option) directory - d:/bin2/msys64/clang64/include/

3) To msvc linker gave 4 libraries (following paths start from d:/bin2/msys64/ folder where MSYS is located):
clang64/lib/libgmp.a
clang64/lib/libgmpxx.a
mingw64/lib/gcc/x86_64-w64-mingw32/10.3.0/libgcc.a
clang64/x86_64-w64-mingw32/lib/libmingwex.a

4) Also I had to add /FORCE option to linker because there were two duplicate symbols between MSYS and MSVC default libraries. This force flag forces linker to ignore duplicate and unresolved symbols.

All above uses static .a libraries, so my final EXE had no external DLL in dependencies (except Windows system DLLs).

After that program ran successfully without errors and at full expected speed. So feeding .a libraries from MSYS to MSVC works quite well.

Also separately I easily compiled MSYS version of static .a libraries of most recent GMP sources through - "./configure && make -j8". But didn't use this version because default prebuilt MSYS GMP version is quite recent and works well.

Last fiddled with by moytrage on 2021-09-18 at 17:47
moytrage is offline   Reply With Quote
Old 2021-09-18, 17:52   #4
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

11,027 Posts
Default

Quote:
Originally Posted by moytrage View Post
Also I'm aware that there exists MPIR library, which should be more Windows-friendly. But right now I need specifically GMP solution.
Can you explain why you need GMP and why MPIR is unsuitable? I know people in the MPIR community and they may be able to help remedy any deficiency MPIR might have.
xilman is offline   Reply With Quote
Old 2021-09-19, 04:40   #5
moytrage
 
Jul 2021

3×11 Posts
Default

Quote:
Originally Posted by xilman View Post
Can you explain why you need GMP and why MPIR is unsuitable?
MPIR is unsuitable for quite minor reasons, because GMP was chosen for our project as a main backend, because our people don't want extra other libraries dependencies, also because it is nice if we use single library everywhere on all OSes.

But first of all I just wanted to check if GMP can be ported to Windows, it will be very great. Of course if it can't then definitely we will use MPIR.

Also from my last post above you can see that I successfully managed to use GMP on MSVC/Windows. But solution is not that clean as it would be if everything was compiled by MSVC only. But still quite acceptable. So GMP with all optimizations in fact can be used on MSVC/Windows.

Can you tell me in short does MPIR have identical interface as GMP? Meaning if we have huge code written and tested for GMP can we just replace GMP with MPIR and code will be compilable and working?
moytrage is offline   Reply With Quote
Old 2021-09-21, 11:39   #6
Happy5214
 
Happy5214's Avatar
 
"Alexander"
Nov 2008
The Alamo City

30716 Posts
Default

Quote:
Originally Posted by moytrage View Post
Also from my last post above you can see that I successfully managed to use GMP on MSVC/Windows. But solution is not that clean as it would be if everything was compiled by MSVC only. But still quite acceptable. So GMP with all optimizations in fact can be used on MSVC/Windows.
It is highly unlikely you're ever going to get GMP to build on MSVC. Looking at the source, it's highly dependent on GNU build tools (autotools, m4, GNU Assembler), with which MSVC just isn't compatible.

Last fiddled with by Happy5214 on 2021-09-21 at 11:39 Reason: Add emphasis
Happy5214 is offline   Reply With Quote
Old 2021-09-21, 12:24   #7
bsquared
 
bsquared's Avatar
 
"Ben"
Feb 2007

3·1,193 Posts
Default

Quote:
Originally Posted by moytrage View Post
Can you tell me in short does MPIR have identical interface as GMP? Meaning if we have huge code written and tested for GMP can we just replace GMP with MPIR and code will be compilable and working?
I believe that is it's goal - it was originally forked from GMP. I have been happily using it for years as a drop-in compatible library with GMP for MSVC builds in several projects. But my projects are not all that big and don't touch many corners of the library.
bsquared is offline   Reply With Quote
Old 2021-09-21, 16:30   #8
Mysticial
 
Mysticial's Avatar
 
Sep 2016

23×43 Posts
Default

Worth noting that there's quite a bit of beef between GMP and MPIR.

The GMP devs hate Windows and anything Microsoft. It's quite obvious from the tone of language in their mailing lists.

This hostility towards Windows is why MPIR was made. So then the GMP devs started hating on MPIR probably because it became a competitor.
Mysticial is offline   Reply With Quote
Old 2021-09-21, 20:33   #9
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

273F16 Posts
Default

Quote:
Originally Posted by Mysticial View Post
This hostility towards Windows is why MPIR was made. So then the GMP devs started hating on MPIR probably because it became a competitor.
Please forgive me for this. But there is a reason why many hate M$.

My own opinion... Their software has been shit for years. They used market manipulation to become dominant just when the critical decisions were being made.

I will never forget when my boss (the CTO) at a Canadian Hospital was tricked into believing the warning messages trying to install Windows 3.0 onto a competitive DOS offering.

He "drank the Kool-Aid" and made a bad decision. I resigned shortly later.

Fast forward to Today, and Microsoft has embraced Open Source. Mostly because of "Cloud Compute".

Suddenly it's no longer a "cancer".

P.S. Just for the record, M$ *did* lose an AntiTrust case. Which was then reversed by a certain Bush.
chalsall is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
build with MSVC 2010 problem Geek2600 Msieve 0 2018-02-12 13:37
PFGW build help (with MSVC 2012 Express) Prime95 Software 5 2013-08-07 23:51
Is it worth the trouble to "upgrade" Windows 8 to Windows 7? ixfd64 Lounge 23 2013-04-13 11:12
Windows 7 Windows Update & Prime95 issue!!! Unregistered Information & Answers 14 2010-04-10 21:47
Compiling GMP-ECM in Windows using MSVC jbristow GMP-ECM 4 2008-04-17 14:42

All times are UTC. The time now is 02:33.


Sat Dec 4 02:33:12 UTC 2021 up 133 days, 21:02, 0 users, load averages: 1.36, 1.31, 1.29

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.