1. Install and configure C++ development environment
Need to install g++, gcc, make and other development environments. There are many tutorials on the Internet, so I won’t repeat them
2. Go to libgmp official website to download the latest gmp package, for example, I downloaded gmp-6.1.2
Unzip
3. Install gmp
Remember to switch administrators! !
$cd gmp-6.1.2
$./configure --enable-cxx
$make
$make check
$sudo make install
4. Configure vscode
Although it is installed, you need to make small changes to the compiled commands if you want to use it in vscode!
Modify it task.json
and add it in the parameter position -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"
}
Then you can write a code and try it~
#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;
}