vs code 配置c/c++环境

1. 编译

通过 code-runner插件 运行编译

安装code-runner后在settings.json中找到code-runner.executorMap,可以看到其中的cpp 文件运行方式为
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir/$fileNameWithoutExt"

2. 调试

c_cpp_properties.json: 这个文件现在的VScode版本已经不需要了

task.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g", 
        "-std=c++11", 
        // "${workspaceFolder}/${file}",
        // "${file}", 
        "${workspaceFolder}/${fileBasenameNoExtension}.cpp",
        "-o", 
        "${workspaceFolder}/${fileBasenameNoExtension}.o",
    ],// 编译命令参数
    "problemMatcher":{
        "owner": "cpp",
        "fileLocation":[
            "relative",
            "${workspaceFolder}/Documents"
        ],
        "pattern":[
            {
                "regexp": "^([^\\s].*)\\((\\d+,\\d+)\\):\\s*(.*)$",
                "file": 1,
                "location": 2,
                //"message": 3
            }
        ]
    },
    "group": {
        "kind": "build",
        "isDefault": true
    }
}
//"command": "g++",

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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.o",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/Documents",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}
//"program": "${workspaceFolder}/${fileBasenameNoExtension}.o",
//"cwd": "${workspaceFolder}",

原文地址:https://www.cnblogs.com/kolane/p/12051269.html