- c_cpp_properties.json - 编译环境相关的设置
打开方式:Ctrl+Shift+P进入命令行,搜索C/C++ Edit configuration
作用:指定头文件路径/编译器路径
{
"configurations": [
{
"name": "Linux", //环境名
"includePath": [
"${workspaceFolder}/**" //指定头文件路径,这里${workspaceFolder}指定的是当前工作目录,如有需要在后面添加“,”后再添加新的路径。
],
"defines": [],
"compilerPath": "/usr/bin/g++", //编译器的路径,可根据自己的安装情况进行设置
"cStandard": "c11",
"cppStandard": "c++17", //设置使用的 C/C++ 标准
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
- task.json - 编译参数设置
打开方式:Ctrl + Shift + p进入命令行,选择 Tasks: Configure Default Build Task
作用:指定编译规则,和preLaunchTask配合使用可以实现自动编译。
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world", //当前编译任务的名字,和preLaunchTask相对应
"type": "shell",
"command": "g++", //编译时执行的程序,调试ros时使用catkin_make DCMAKE_BUILD_TYPE=Debug
"args": ["-g", "-o", "helloworld", "helloworld.cpp"], //传递给 command 的参数,也就是编译参数
"group": {
"kind": "build",
"isDefault": true //为 True 时,用户可以通过 Ctrl+Shift+B 直接运行编译任务
}
}
]
}
- launch.json - 调试相关的参数
打开方式:Ctrl+Shift+p 打开命令行,键入关键字 "launch",选择 "Debug:Open launch.json" -> "C++(GDB/LLDB)。
作用:调试程序,如设置debug,设置可执行文件的路径,预编译等
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld", //可执行文件的完整路径
"args": [],
"stopAtEntry": false, //是否在 main 函数处暂定执行
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //在打开外部终端执行程序,而不是在 VSCode 的控制台中运行
"MIMode": "gdb",
"preLaunchTask":“helloworld”,//和task中的label对应
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}