Linux/Windows系统,使用vscode调试C/C++的配置分享(launch和tasks两个json)

下定决心,准备学习Linux开发,由于在Windows上一直用vscode,在Linux上也准备用vscode,配置其他东西的过程顺风顺水,直到开始配置launch和tasks……

一下午时间,参考了无数网站,无数大神的方法,不断出现各种错误,一路磕磕绊绊,但是最终还是配置好了,下面奉上我的配置,分享给有需要的人:

launch.json

Linux↓

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "preLaunchTask": "build",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Windows↓

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "preLaunchTask": "build",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/MinGW/bin/gdb.exe", // 这里修改GDB路径为安装的mingw64的bin下的gdb.exe路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }]
}

tasks.json

Linux↓

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": ["-g","${file}","-std=c++11","-o","${fileBasenameNoExtension}.out"]
        }
    ]
}

Windows↓

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "windows": {
                "command": "g++",
                "args": [
                    "-ggdb",
                    "\"${file}\"",
                    "--std=c++11",
                    "-o",
                    "\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
                ]
            }
        }
    ]
}

我这样配出来有两个问题:1、Windows中,无法使用中文路径(也可能是我这个版本的软件本身问题);2、Linux下,只能调用vscode自带的终端和控制台,把【“externalConsole”: true】改成【“externalConsole”: false】后,又无法像Windows一样愉快地使用系统自带终端,求大神帮忙

我这里用的是kali linux,使用了root账户,其实不用root账户也是可以的,其他发行版本的Linux应该也可以

Linux version 5.4.0-kali3-amd64 ([email protected]) (gcc version 9.2.1 20200104 (Debian 9.2.1-22)) #1 SMP Debian 5.4.13-1kali1 (2020-01-20)

谨以此文代表我在Linux开发这条“不归路”上征程的开端(勿喷)
——某大学计算机科学与技术专业大一学生

你可能感兴趣的:(Linux/Windows系统,使用vscode调试C/C++的配置分享(launch和tasks两个json))