VS Code 项目的配置文件位于.vscode文件夹下。本文将具体说明在vscode中如何操作生成.vscode 文件夹下的三个配置文件:
(1). tasks.json (compiler build settings) ,负责编译
(2). launch.json (debugger settings),负责调试
(3). c_cpp_properties.json (compiler path and IntelliSense settings),负责更改路径等设置
首先安装C++拓展。点击在vscode界面最左侧的Extensions图标(打开快捷键:ctrl+shift+X),搜索“C/C++”,点击进行安装。
1、创建 tasks.json
告诉 VS Code 如何构建(编译)程序
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
2、创建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": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
3、创建c_cpp_properties.json
更多地控制 C/C++ 扩展,它允许你更改设置,例如编译器的路径、包含路径、C++ 标准(默认为 C++17)
{
"configurations": [
{
"name": "Linux",
"includePath": ["${workspaceFolder}/**"],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
4、settings.json
对vscode的一些定制化内容
vscode的setting.json的配置 - 简书
针对Apollo的开发调试(待补充)
远程调试:
? ? ? ? ssh:vscode通过ssh远程访问,或登入docker容器均无障碍
详解Linux下使用vscode编译运行和调试C/C++ - 知乎
Ubuntu上vscode编译C++_Xu小亿的博客-CSDN博客_ubuntu vscode 编译
使用 vscode-insiders 的docker扩展 调试Apollo项目_Rancho2018的博客-CSDN博客_vscode-insiders
使用Visual Studio Code编译、调试Apollo项目_知行合一2018的博客-CSDN博客_apollo vscode
自动驾驶开发者说|框架|如何用vscode调试apollo? - 知乎
VS Code调试问题记录_WangN2的博客-CSDN博客
复杂环境变量的VSCode调试方法_WangN2的博客-CSDN博客
|