目录结构
$ tree -a
.
├── helloworld
├── helloworld.cpp
└── .vscode
├── c_cpp_properties.json
├── launch.json
├── settings.json
└── tasks.json
1 directory, 6 files
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c89",
"cppStandard": "c++98",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", //配置名称,会在启动配置的下拉菜单中显示
"type": "cppdbg", //配置类型,只能为cppdbg
"request": "launch", //请求类型,可以为launch或attach
"program": "${workspaceFolder}/${fileBasenameNoExtension}", //将要调试的程序的路径 文件夹/helloworld
"args": [], //调试时传递给程序的命令行参数
"stopAtEntry": false, //设为true程序会暂停在入口处
"cwd": "${workspaceFolder}", //调试程序时的工作目录
"environment": [], //环境变量
"externalConsole": false, //调试时是否显示控制台窗口
"MIMode": "gdb", //指定连接的调试器,可以为gdb或lldb
"miDebuggerPath": "/usr/bin/gdb", //gdb路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build" //调试开始前执行的任务,一般为编译程序
}
]
}
settings.json
{
"code-runner.runInTerminal": true,
"terminal.integrated.fontFamily": "monospace" //终端字体。默认的话间隔过大,改为monospace,这个字体win、linux、macos基本都有
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build", //在launch.json文件中有用到
"type": "shell",
"command": "g++",
"args": [
"-g", "${fileBasename}","-o","${fileBasenameNoExtension}","-O2"//g++ -g helloworld,cpp -o helloworld -O2
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}