Ine*_*nex 3 c++ makefile vscode-debugger
我有问题,我有用 C++ 编写的 Make 项目(多个 C++ 文件)。我正在尝试使用 VScode 调试器来调试它,但它只是冻结和 dats 所有,如何修复调试器 VSCodes json 中的哪些参数我必须更改等?
项目文件夹配置:
生成文件
exe
Run Code Online (Sandbox Code Playgroud)
src(所有 o 和 cpp h 文件都将被存储的
文件夹)在 SRC 文件夹中:
main.cpp
WGForeCast.h
WGForeCast.cpp 等
我的任务.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "make",
"args":["${workspaceFolder}/Makefile"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我的发射
{
// 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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/Pusk",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
好吧,我找到了解决方案:
首先
在 Makefile 中,您需要将选项 -g 标志添加到编译器以使用,“ -g ”:生成由基于 gdb 的调试器使用的调试信息 添加标志示例
CC=g++ -g -Wall
Run Code Online (Sandbox Code Playgroud)
以防万一,在继续之前使用添加的标志重建您的项目;
其次,你需要改变task.json在您的项目
要创建一个launch.json文件,在VS代码(打开你的项目文件夹中的文件>打开文件夹),然后选择Debug视图顶部栏上的配置齿轮图标。选择gdb (for LInux) 然后将生成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": "Pusk", //I named it Pusk because i can
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/Pusk", //path to your programs exe and exe name
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
第三,我们必须配置task.json(基本上它有点脚本来使用 Makefile 而不是默认编译器来启动您的程序)。
创建 task.json
CC=g++ -g -Wall
Run Code Online (Sandbox Code Playgroud)
像这样更改task.json(可能不需要那么复杂的只是¯(?)/¯ )
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "make", //its like writing in console make //btw you can others commands like clean make build etc
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
按Ctrl+Shift+B重建您的项目 (现在就像在控制台中 make,因为我们更改了 task.json)
DATS ALL!你现在可以使用调试器了!!!
源代码- >参见“在 vs 代码中调试”一文