mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Software (https://www.mersenneforum.org/forumdisplay.php?f=10)
-   -   GMP for Windows (MSVC)? (https://www.mersenneforum.org/showthread.php?t=27143)

moytrage 2021-09-18 06:32

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.

Prime95 2021-09-18 16:26

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

[/CODE]

moytrage 2021-09-18 17:24

[QUOTE=Prime95;588112]if you get MSVC to build it, do post instructions on how to do it![/QUOTE]

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.

xilman 2021-09-18 17:52

[QUOTE=moytrage;588093]Also I'm aware that there exists MPIR library, which should be more Windows-friendly. But right now I need specifically GMP solution.[/QUOTE]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.

moytrage 2021-09-19 04:40

[QUOTE=xilman;588117]Can you explain why you need GMP and why MPIR is unsuitable?[/QUOTE]

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?

Happy5214 2021-09-21 11:39

[QUOTE=moytrage;588138]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 [B]if everything was compiled by MSVC only[/B]. But still quite acceptable. So GMP with all optimizations in fact can be used on MSVC/Windows.[/QUOTE]

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.

bsquared 2021-09-21 12:24

[QUOTE=moytrage;588138]
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?[/QUOTE]

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.

Mysticial 2021-09-21 16:30

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.

chalsall 2021-09-21 20:33

[QUOTE=Mysticial;588341]This hostility towards Windows is why MPIR was made. So then the GMP devs started hating on MPIR probably because it became a competitor.[/QUOTE]

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.


All times are UTC. The time now is 13:53.

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