我一直在尝试为我的Mac设置Visual Studios Code,但是我在launch.json和task.json中遇到了问题。我将使用Clang编译器。
我尝试遵循Microsoft的文档,但它设置了.JSON文件来编译和调试一个名为helloworld.c的程序,我只想配置launch.json和task.json来构建和调试任何给定的.c/.cpp文件。我对.JSON文件不够熟练,不知道自己在做什么或做任何有效的事情。
tasks.json:
我尝试遵循Microsoft的文档,但它设置了.JSON文件来编译和调试一个名为helloworld.c的程序,我只想配置launch.json和task.json来构建和调试任何给定的.c/.cpp文件。我对.JSON文件不够熟练,不知道自己在做什么或做任何有效的事情。
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "clang++ build active file",
"type": "shell",
"command": "clang++",
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"args": [
"-std=c++17",
"-stdlib=libc++",
"--debug"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"absolute"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
{
"type": "shell",
"label": "clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json:
"version": "0.2.0",
"configurations": [
{
"name": "clang build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "clang build",
"miDebuggerPath": "/usr/bin/lldb"
}
]
}