通过 launch 配置preLaunchTask编译文件,然后启动调试;过程中编译task中需要自己补写编译的命令;常见错误?error: ld returned 1 exit status
未编译源文件:undefined reference to 通过 -g 参数加入cpp文件 如/src_dir/*/* (?通配)
?头文件搜索位置没指定:No such file or directory 通过 -I 加入 /head_dir/*?
.vscode/launch.json?
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 调试启动",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "Task Name",
"program": "${workspaceFolder}/CodeCraft-2022",
"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
}
]
}
]
}
.vscode/tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "Task Name",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"main.cpp","source/**/*",
"-I",
"inlcude_A/*","include_B/*",
"-o",
"${workspaceFolder}/main"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
.vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
|