首先创建tasks.json文件,用于编译项目。
1、自己先新建一个 .vscode 文件夹,然后command+shift+p 弹出任务框,选择Tasks:Configure Task,生成tasks.json,tasks.json 是用来配置编译所需的相关参数。
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"-std=c++11",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: /usr/bin/clang"
}
]
}
2、然后再创建一个 launch.json 文件, 用于加载taks.json任务并编译项目,然后调试
launch.json 具体配置如下,(要调试的程序 编译时必须有"-g"参数,用于添加调试信息)
{
// 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": "g++ - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
//"request":"attach",
"program": "${workspaceFolder}/main",
//"args": ["-c" ,"${workspaceFolder}/trunk/conf/srs.conf"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
//"preLaunchTask": "C/C++: clang 生成活动文件" // 调试之前要执行的任务,和tasks.json中的label必须相同
}
]
}
然后就可以运行---》启动调试了