1.安装配置C++开发环境
需要安装g++, gcc, make等开发环境, 网上有很多教程,不再赘述
2.去libgmp官网下载最新的gmp包,例如我下载的是gmp-6.1.2
解压即可
3.安装gmp
记得切换管理员!!
$cd gmp-6.1.2
$./configure --enable-cxx
$make
$make check
$sudo make install
4.配置vscode
虽然安装好了,但是想要在vscode中使用需要对编译的命令进行小小的修改!
修改task.json
, 在参数位置添加-lgmp
即可。
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lgmp" // 添加此处
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
然后就可以写个代码试试看了~
#include <gmp.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
mpz_t a,b,c;
mpz_init(a);
mpz_init(b);
mpz_init(c);
gmp_scanf("%Zd%Zd",a,b);
mpz_add(c,a,b);
gmp_printf("c= %Zd\n",c);
return 0;
}