之前在知乎直接照搬了大佬谭九鼎的json,以为直接就可以在vscode上跑,结果出现{prelaunchtask“g++”已终止,退出代码为1},一度放弃,后面照搬了另一家的json文件以后恢复正常,经过排除发现是task文件出现问题,特在此贴出,头一次接触json看不太懂,请大佬帮忙分析一下具体问题在哪里。
第一份task.json为正常运行版本
{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${file}.exe",
], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
第二份task.json为出现上述问题版本
{
"version": "2.0.0",
"tasks": [{
"label": "g++",
"command": "gcc",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g",
"-Wall",
"-static-libgcc",
"-fexec-charset=GBK",
],
"type": "process",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
}]
}
灵光一闪,把第二个json的command从gcc改成g++就正常使用了,但是不明白是为什么,请大佬解释一下这里的command是什么,将command改为gdb和gcc均不可使用。