vscode+wsl+mingw编译调试配置样例

vscode使用wsl(ubuntu)编译调试样例,使用mingw编译调试样例

1.安装vscode及插件如下

可以参考使用WSL+VSCode快速C++入门_wsl c++ setting.json_逗神大人的博客-CSDN博客

2.安装wsl和mingw

mingw从官方下载较慢,可以从下面下载

https://download.csdn.net/download/qjm1995/11094533

3.使用wsl编译和调试

配置文件详细如下:

c_cpp_properties.json

{
    "configurations": [{
        "name": "WSL",
        "intelliSenseMode": "gcc-x64",
        "compilerPath": "/usr/bin/g++",
        "includePath": [
            "${workspaceFolder}/**"
        ],
        "defines": [],
        "cStandard": "c11",
        "cppStandard": "c++17"
    }],
    "version": 4
  }

launch.json

{
    "version": "0.2.0",
    "configurations": [{
        "name": "hello Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "/mnt/d/vscode_work/wsl_hello/hello",
        "args": [],
        "stopAtEntry": false,
        "cwd": "/mnt/d/vscode_work/wsl_hello",
        "environment": [],
        "externalConsole": true,
        "windows": {
            "MIMode": "gdb",
            "setupCommands": [{
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }]
        },
        "pipeTransport": {
            "pipeCwd": "",
            "pipeProgram": "c:\\windows\\sysnative\\bash.exe",
            "pipeArgs": ["-c"],
            "debuggerPath": "/usr/bin/gdb",
        },
        "sourceFileMap": {
            "/mnt/d": "d:\\"
        }
    }]
  }

settings.json

{
    "terminal.external.windowsExec": "C:\\WINDOWS\\System32\\bash.exe",
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"
    "files.associations": {
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp",
        "functional": "cpp",
        "iterator": "cpp",
        "numeric": "cpp"
    }
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "process",
            "command": "bash.exe",
            "args": [
                "-c",
                "scons"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
  }

SConstruct

env=Environment(CCFLAGS = ['-g','-std=c++11','-Wall']) 
env.Program('hello', Glob('*.cpp'), LIBS = ['m'], LIBPATH = ['/usr/lib'])

4.使用mingw编译和调试

配置文件详细如下:

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}",
                "D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\MinGW\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

launch.json


{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "hello Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/hello.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build hello"
        }
    ]
}

settings.json

{
    "files.associations": {
        "array": "cpp",
        "atomic": "cpp",
        "*.tcc": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "istream": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp",
        "functional": "cpp",
        "iterator": "cpp",
        "numeric": "cpp"
    }
}

tasks.json


{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build hello",
            "type": "shell",
            "command": "g++",
            "args": [
                "*.cpp",
                "-g",
                "-o",
                "hello.exe",
                "-std=c++11",
                "-Wall",
                "-lm",
                "-L.",
                "-I."
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
}

PS:

https://www.youtube.com/watch?v=ZFtrZh20CAc

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值