How to build GMP in MSYS2?

1.5k views Asked by At

I would like to use GMP on windows, and I need to build static programs. (which means that, if anyone can provide another solution to compile win32 x86_64 programs using libgmp, I will also appreciate it.)

Now I have msys2 installed, and in it I have executed

pacman -S base-devel gcc 

and then I downloaded gmp-6.2.0.tar.lz from gmplib.org and extracted it to somewhere, like

C:\Users\xxx\gmp-6.2.0

Then I, using msys2 mingw64, entered this directory and executed

./configure
make
make check
make install

The first two commands seems to be fine, the output seems to be right. However, make check didn't provide me with whether the make is right or not. At the end of its output it says,

make[5]: Leaving directory '/c/Users/Fred/gmp-6.2.0/tests/cxx'
make[4]: Leaving directory '/c/Users/Fred/gmp-6.2.0/tests/cxx'
make[3]: Leaving directory '/c/Users/Fred/gmp-6.2.0/tests/cxx'
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/tests'
Making check in mpn
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/mpn'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/mpn'
Making check in mpz
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/mpz'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/mpz'
Making check in mpq
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/mpq'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/mpq'
Making check in mpf
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/mpf'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/mpf'
Making check in printf
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/printf'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/printf'
Making check in scanf
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/scanf'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/scanf'
Making check in rand
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/rand'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/rand'
Making check in cxx
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/cxx'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/cxx'
Making check in demos
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/demos'
Making check in calc
make[3]: Entering directory '/c/Users/Fred/gmp-6.2.0/demos/calc'
make  check-am
make[4]: Entering directory '/c/Users/Fred/gmp-6.2.0/demos/calc'
make[4]: Nothing to be done for 'check-am'.
make[4]: Leaving directory '/c/Users/Fred/gmp-6.2.0/demos/calc'
make[3]: Leaving directory '/c/Users/Fred/gmp-6.2.0/demos/calc'
Making check in expr
make[3]: Entering directory '/c/Users/Fred/gmp-6.2.0/demos/expr'
make[3]: Nothing to be done for 'check'.
make[3]: Leaving directory '/c/Users/Fred/gmp-6.2.0/demos/expr'
make[3]: Entering directory '/c/Users/Fred/gmp-6.2.0/demos'
make[3]: Nothing to be done for 'check-am'.
make[3]: Leaving directory '/c/Users/Fred/gmp-6.2.0/demos'
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/demos'
Making check in tune
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/tune'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/tune'
Making check in doc
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0/doc'
make[2]: Nothing to be done for 'check'.
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0/doc'
make[2]: Entering directory '/c/Users/Fred/gmp-6.2.0'
make[2]: Leaving directory '/c/Users/Fred/gmp-6.2.0'
make[1]: Leaving directory '/c/Users/Fred/gmp-6.2.0'

And make install ended up in similar messages. At last when I tried to compile programs, it says,

/usr/lib/gcc/x86_64-pc-msys/9.3.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lgmp

As a matter of fact, I am not a professional programmer so I'm not quite sure about how to install GMP for mingw. I would be deeply grateful if anyone can tell me how to do this from scratch.

1

There are 1 answers

2
Yutsing On BEST ANSWER

With the help of @HolyBlackCat, I solved this problem and successfully compiled my programs. Here is the process:

Install msys2

  1. Download the executable file from msys2.org and install msys2. You will get three shortcuts in your opening menu: MSYS MinGW 32-bit, MSYS2 MinGW 64-bit and MSYS2 MSYS. The difference between them is the PATH. MSYS's path is /usr/bin, while MinGW 64-bit's path includes /mingw64/bin.
  2. Install necessary packages. Run the following commands:
$ pacman -Syu
$ pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gmp

Compile your programs

  1. Open MSYS2 MinGW 64-bit
  2. Use x86_64-w64-mingw32-gcc rather than gcc to compile. (If you didn't install gcc, you can simply use gcc to compile.) If you are using other shell, use the full path /mingw64/bin/x86_64-w64-mingw32-gcc

Other info

If you needs to use autoconf tools, you can install them with

$ pacman -S base-devel