- 如果右上角没有 run and debug button 记得把 setting 里 Intelli Sense Engine 改成 default,以及 Debug Shortcut 打开
- 如果 cpp 文件提示 header not found,那需要在
c_cpp_properties.json
中把compilerPath
,添加上 - debug 的时候,默认他好像是会自动 build 的,当然也可以自己写 prelaunchtask,它的具体属性值需要和 build task 的 lable 一样;自己写的时候要注意下 cwd 这个属性。
其实大部分解决方案都可以从 vscode 官方文档里面找到
贴几个 .vscode 下面的配置文件记录一下。
launch.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22000.0",
"cStandard": "c17",
"cppStandard": "c++17",
"compilerPath": "D:/software/mingw64/bin/cl"
}
],
"version": 4
}
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}/test.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:/software/mingw64/bin/gdb.exe",
"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++.exe build active file",
},
]
}