vscode配置cpp调试环境
本文于 852 天之前发表,文中内容可能已经过时。
- 安装vscode插件
- c/c++
- cmake
- cmake-tool
- 安装程序
1
sudo apt install cmake clang gdb
- 配置vscode
c_cpp_properties.json
菜单栏【查看】【命令面板…】,输入关键词”C/C++ edit”,选择匹配到的命令”C/C++: Edit Configurations (json)”1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "${default}",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}添加task.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59{
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}" //需要进入到我们执行tasks任务的文件夹中
},
"tasks": [
{
"type": "shell",
"label": "mkdir",
"group": {
"kind": "build",
"isDefault": true
},
"command": "mkdir",
"args": [
"-p",
"build"
]
},
{
"type": "shell",
"label": "cmake",
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder}/build"
},
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder}/build"
},
"command": "make",
"args": [
"-j4"
]
},
{
"label": "build",
"dependsOrder": "sequence",
"dependsOn": [
"mkdir",
"cmake",
"make"
]
}
]
}这里实际上将手动的make过程程序化,有需要可以对task任务加减,如:添加rm -rf CMakeCache.txt命令
添加launch.json
实际的调试入口,启动task任务1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "C++ launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/viewer/gltf-viewer",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
- 执行
写好CMakeLists.txt
ctrl+shift+D 点击launch任务
done