vscode打开一个目录后生成.vscode目录,如果配置有问题,可以把.vscode删掉。
这是后进入左侧的run and debug ,默认是没有的,选择C++(GDB/LLDB) -> g++ -build and debug active file ,然后Terminal -> Configure Default Build Task -> C++ g++ build active file
这时候出现task.json,修改
f
i
l
e
D
i
r
n
a
m
e
/
{fileDirname}/
fileDirname/{fileBasenameNoExtension}为
f
i
l
e
D
i
r
n
a
m
e
/
{fileDirname}/
fileDirname/{fileBasenameNoExtension}.out,这样的好处是可以在.gitignore文件里面方便的忽略掉.out文件
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
同时修改launch.json,program后面的
f
i
l
e
D
i
r
n
a
m
e
/
{fileDirname}/
fileDirname/{fileBasenameNoExtension}也加上.out
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/bin/gdb"
}
]
}
前面这部分都是用g++配置调试的,换成clang++也是可以的,用的都是默认配置,只增加了.out,对应的task和launch文件如下:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: clang++ build active file",
"miDebuggerPath": "/bin/lldb"
}
]
}
|