WIndows+VScode中导入GMP(成功)

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

如果想在ubuntu 下的vscode 中使用gmp,请看这篇文章

https://www.cnblogs.com/cyssmile/p/12588767.html

posted @ 2020-05-10 12:11  cyssmile  阅读(2078)  评论(2编辑  收藏  举报