如何在 MSYS2 中构建 GMP?

How to build GMP in MSYS2?

我想在 windows 上使用 GMP,我需要构建静态程序。 (这意味着,如果有人能提供另一种使用 libgmp 编译 win32 x86_64 程序的解决方案,我也将不胜感激。)

现在我安装了msys2,并在其中执行了

pacman -S base-devel gcc 

然后我从 gmplib.org 下载了 gmp-6.2.0.tar.lz 并将其解压到某个地方,比如

C:\Users\xxx\gmp-6.2.0

然后我用msys2 mingw64进入这个目录执行

./configure
make
make check
make install

前两个命令似乎没问题,输出似乎是正确的。 但是, make check 并没有告诉我 make 是否正确。在其输出的末尾,它说,

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'

并且 make install 以类似的消息结束。最后,当我尝试编译程序时,它说,

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

事实上,我不是专业的程序员,所以我不太清楚如何安装GMP 对于 mingw。如果有人能告诉我如何从头开始,我将不胜感激。

在@HolyBlackCat的帮助下,我解决了这个问题并成功编译了我的程序。过程如下:

安装 msys2

  1. msys2.org下载可执行文件并安装msys2。您将在打开的菜单中获得三个快捷方式:MSYS MinGW 32 位、MSYS2 MinGW 64 位和 MSYS2 MSYS。它们之间的区别在于 PATH。 MSYS的路径是/usr/bin,而MinGW 64-bit的路径包括/mingw64/bin.
  2. 安装必要的软件包。 运行 以下命令:
$ pacman -Syu
$ pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gmp

编译你的程序

  1. 打开 MSYS2 MinGW 64 位
  2. 使用x86_64-w64-mingw32-gcc而不是gcc来编译。 (如果没有安装gcc,直接用gcc编译即可。)如果使用其他shell,使用全路径/mingw64/bin/x86_64-w64-mingw32-gcc

其他信息

如果你需要使用autoconf工具,你可以安装它们

$ pacman -S base-devel