环境
- Win10+WSL-Ubuntu子系统
- 编译器:GCC
vscode配置
插件配置
开发配置
以作业工程化编程实战callback接口为例,编译、调试项目时,需要分别配置tasks.json文件与lanuch.json文件
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${fileDirname}/linktable.c",
"${fileDirname}/menu.c",
"-o",
"${fileDirname}/link"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
由于该项目有两个c文件linktable.c,menu.c需要编译,因此需要将tasks.json中的"args"一栏修改为"${fileDriname}/linktable.c"以及"${fileDirname}/menu.c"。参数列表中的"-g"是传递给gcc调用的,需要这个参数才能保证debug的正常进行。"-o"参数后是可执行程序的信息,在这里我将生成的程序命名为"link"。
lanuch.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": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "link",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
lanuch.json文件只需要修改"program"参数,将其修改为需要调试的程序名即可。