简体   繁体   English

如何在 MSYS2 中构建 GMP?

[英]How to build GMP in MSYS2?

I would like to use GMP on windows, and I need to build static programs.我想在 windows 上使用 GMP,我需要构建 static 程序。 (which means that, if anyone can provide another solution to compile win32 x86_64 programs using libgmp, I will also appreciate it.) (这意味着,如果有人可以提供另一种使用 libgmp 编译 win32 x86_64 程序的解决方案,我也会很感激。)

Now I have msys2 installed, and in it I have executed现在我安装了 msys2,并在其中执行了

pacman -S base-devel gcc 

and then I downloaded gmp-6.2.0.tar.lz from gmplib.org and extracted it to somewhere, like然后我从 gmplib.org 下载了 gmp-6.2.0.tar.lz 并将其解压到某个地方,比如

C:\Users\xxx\gmp-6.2.0

Then I, using msys2 mingw64, entered this directory and executed然后我,使用msys2 mingw64,进入这个目录并执行

./configure
make
make check
make install

The first two commands seems to be fine, the output seems to be right.前两个命令似乎没问题,output 似乎是正确的。 However, make check didn't provide me with whether the make is right or not.但是, make check 并没有告诉我 make 是否正确。 At the end of its output it says,在其 output 的末尾,它说,

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.并且 make install 以类似的消息结束。 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.事实上,我不是专业程序员,所以我不太确定如何为 mingw 安装 GMP。 I would be deeply grateful if anyone can tell me how to do this from scratch.如果有人能告诉我如何从头开始做这件事,我将不胜感激。

With the help of @HolyBlackCat, I solved this problem and successfully compiled my programs.在@HolyBlackCat 的帮助下,我解决了这个问题并成功编译了我的程序。 Here is the process:这是过程:

Install msys2安装msys2

  1. Download the executable file from msys2.org and install msys2.msys2.org下载可执行文件并安装 msys2。 You will get three shortcuts in your opening menu: MSYS MinGW 32-bit, MSYS2 MinGW 64-bit and MSYS2 MSYS.您将在打开的菜单中获得三个快捷方式:MSYS MinGW 32 位、MSYS2 MinGW 64 位和 MSYS2 MSYS。 The difference between them is the PATH.它们之间的区别在于 PATH。 MSYS's path is /usr/bin, while MinGW 64-bit's path includes /mingw64/bin. MSYS 的路径是/usr/bin,而MinGW 64-bit 的路径包括/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打开 MSYS2 MinGW 64 位
  2. Use x86_64-w64-mingw32-gcc rather than gcc to compile.使用 x86_64-w64-mingw32-gcc 而不是 gcc 来编译。 (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 (如果你没有安装gcc,你可以简单地使用gcc来编译。)如果你使用其他shell,使用完整路径/mingw64/bin/x86_64-w64-mingw32-gcc

Other info其他信息

If you needs to use autoconf tools, you can install them with如果你需要使用 autoconf 工具,你可以安装它们

$ pacman -S base-devel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM