windows + vs2019 (最后一步有問題)
ubuntu下安裝成功,unbuntu下安裝在本文后面
1.先安裝cygwin
官網 https://www.cygwin.com/install.html
2. 如果以前安裝過cygwin
可進入安裝目錄執行,比如我這是在D:\cygwin64
setup-x86_64.exe -q -P libgmp-devel -P gcc -P g++ -P make
等待安裝結束
3. 下載GMP
https://gmplib.org/download/gmp/gmp-6.2.0.tar.xz
. 4. 打開cygwin終端
將剛下下好gmp壓縮包拷貝到要解壓路徑下,比如我放在D:\GMP
tar -xvf gmp-6.2.0.tar.xz
cd ./gmp-6.2.0
./configure --disable-static --enable-shared --enable-cxx
make
make check
make install
這里我沒有設置安裝路徑,提示默認安裝路徑在 /usr/local,比如我的在D:\cygwin64\usr\local
automake 讀取 Makefile.am 來產生 Makefile.in, configure 讀取 Makefile.in 來產生 Makefile ,make 使用Makefile
遇到問題
checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).
解決安裝m4
可以通過apt-cyg 安裝

apt-cyg install m4
也可以這樣
setup-x86_64.exe -q -P m4
ctrl+ F5 添加launch.json,內容如下,可以按照我的模板進行修改。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cpp.exe - 生成和調試活動文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "為 gdb 啟用整齊打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
ctrl + shit + p 添加tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "shell: g++.exe build active file",
"command": "D:\\cygwin64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\main.out",
"-lgmpxx",
"-lgmp"
],
"options": {
"cwd": "D:\\cygwin64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\cygwin64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\main.exe",
"-lgmpxx",
"-lgmp"
],
"options": {
"cwd": "D:\\cygwin64\\bin"
}
},
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\cygwin64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\cygwin64\\bin"
}
}
]
}
添加c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:\\cygwin64\\usr\\local\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "D:\\cygwin64\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
如果cygwin 中沒有安裝gdb,可以找到cygwin安裝包setup-x86_64.exe,在控制台運行
setup-x86_64.exe -q -P gdb
測試結果

后記(unbuntu下配置)
搞了半天導入到VScode下還是有錯,ubuntu真香。
sudo apt-get install libgmpxx4ldbl
如果沒有裝m4
sudo apt-get install m4
到此安裝完畢
測試代碼
#include<gmpxx.h>
#include<iostream>
using namespace std;
int main()
{
mpz_t x;
mpz_init(x);
cin>>x;
mpz_mul(x,x,x);
cout<<x<<endl;
mpz_clear(x);
return 0;
}
編譯命令
g++ testGmp.cpp -o test.o -lgmpxx -lgmp
