GMP用来做大数运算还是很方便的,以前没在Mac上安装过,修订新版《面向算法设计的数据结构(C++语言版)》的时候要加点内容,所以安装了一个。
目前系统是Big Sur 11.1,属于新鲜尝试,下载了gmp-6.2.1并解压(注意要下载gmp-6.2.1.tar.xz
就不用lz解压了),放在/usr/local/
目录下。
一路安装:
cd gmp-6.2.1/
./configure
make
make check
sudo make install
本来include <gmp.h>
在命令行下就可以随便使用了,可惜我试了一下XCode,太麻烦,解决方案:
Search Paths > Header Search Paths
要加上/usr/local/include
。Search Paths > Library Search Paths
要加上/usr/local/lib
。Linking > Other Linker Flags
要加上-lgmp
。
本来以为没问题了,最后报错:
ld: symbol(s) not found for architecture arm64
。 仔细一看,之前我为了追求速度调了Release
模式,默认Build Active Artchitecture
为No
,但是GMP这个似乎还不支持arm64
,于是改了Build Active Artchitecture
为Yes
就好了,或者Excluded Artchitectures
把arm64
排除掉也可以。
警告提示:ld: warning: ignoring file /usr/local/lib//libgmp.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
,希望能有M1芯片的朋友测试一下。
似乎Homebrew有相关讨论,等我有空看看:
Get GMP building on Apple Silicon #57315
ghc: apply arm64 compatibility patch to static gmp #57892