我有问题,我有一个用C ++编写的Make project(多个c ++文件)。我正在尝试使用VScode调试器对其进行调试,但它只会冻结并全部删除,如何修复调试器VSCodes json中的哪些参数我必须更改e.t.c?项目文件夹配置:
Makefile
exe
src(存储/将存储所有o和cpp h文件的文件夹)在SRC文件夹中:main.cppWGForeCast.hWGForeCast.cpp等
我的task.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"]
}
]
}
我的发布会
{
// 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
}
]
}
]
}
我找到了解决方法:第一在Makefile中,需要向编译器添加选项-g标志才能使用,“ -g”:生成基于gdb的调试器使用的调试信息。添加标志示例
CC=g++ -g -Wall
以防万一,在继续操作之前用添加的标记重建项目;
第二,您需要在项目中更改task.json要创建launch.json文件,请在VS Code中打开项目文件夹([文件>打开文件夹),然后在“调试”视图顶部栏上选择“配置齿轮”图标。选择gdb(对于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
}
]
}
]
}
第三,我们必须配置task.json(基本上是一种脚本,可以使用Makefile而不是默认的编译器来启动您的程序)。要创建task.json
1)Open a folder with vscode
2)Hit F1
3)Select "Tasks: Configure Task Runner"
4)Hit Enter and vscode will create a sample task.json for you
像这样更改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
}
}
}
]
}
通过按Ctrl + Shift + B重建项目,它现在就像在控制台中的make,因为我们更改了task.json)全部日期!您现在可以使用调试器!!来源-> see "debug in vs code" article