0

我想在 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

事实上,我不是专业程序员,所以我不太确定如何为 mingw 安装 GMP。如果有人能告诉我如何从头开始执行此操作,我将不胜感激。

4

1 回答 1

0

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

安装 msys2

  1. 从msys2.org下载可执行文件并安装 msys2。您将在打开菜单中获得三个快捷方式:MSYS MinGW 32 位、MSYS2 MinGW 64 位和 MSYS2 MSYS。它们之间的区别在于 PATH。MSYS 的路径是 /usr/bin,而 MinGW 64 位的路径包括 /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
于 2020-08-03T12:13:47.597 回答