首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在VSCode中配置c++调试器

在VSCode中配置c++调试器
EN

Stack Overflow用户
提问于 2021-07-03 04:41:27
回答 1查看 101关注 0票数 0

我最近搬到了VSCode,我有点迷路了。

如果我使用以下控制台命令编译程序

代码语言:javascript
运行
复制
g++ -Wall -o main main.cpp src/*.cpp -I included

它将正确编译并生成.exe文件。

但是我有一个bug,所以我想使用调试器来了解发生了什么。当我在VSCode中点击run -> star debuggin时,对于我包含的一个文件,我得到一个控制台消息“不是这样的文件或目录”。所以,我想我的launch.json中有一些错误的配置

launch.json

代码语言:javascript
运行
复制
    {
    // 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": "g++.exe - Compilar y depurar el archivo activo",
            "type": "cppdbg",
            "request": "launch",
            "program": "C:\\Users\\Don\\Desktop\\IColections\\main.exe",
            "args": ["-I[included/*/*.h]"],
            "stopAtEntry": false,
            "cwd": "C:\\Users\\Don\\Desktop\\IColections",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Habilitar la impresión con sangría para gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe compilar archivo activo"
        }
    ]
}

我不太理解,我应该在args或环境中放置什么?

编辑:

这是错误消息

代码语言:javascript
运行
复制
C:\MinGW\bin\g++.exe -g *.cpp -o C:\Users\Don\Desktop\IColections\main.exe
main.cpp:2:31: fatal error: ../included/Fruta.h: No such file or directory
 #include "../included/Fruta.h"
                               ^
compilation terminated.

这是main.cpp

代码语言:javascript
运行
复制
#include <iostream>
#include "../included/Fruta.h"
#include "../included/Uva.h"
#include "../included/Naranja.h"
#include "../included/List.h"
#include "../included/List_Iterator.h"

int main(){
    
    ICollection* fruta = new List;
    
    Uva* misUvas = new Uva;
    misUvas->setKg(80.5);
    misUvas->setRacimos(15000);

    Naranja* misNaranjas = new Naranja;
    misNaranjas->setKg(200);
    misNaranjas->setNaranjas(1000);

    fruta->agregar(misNaranjas);
    fruta->agregar(misUvas);

    IIterator* it = dynamic_cast<List*> (fruta)->getIterator();    

    ICollectible* elem;
    Fruta* frut;

    if(!it->hasCurrent()){
    }

    while(it->hasCurrent()){ 
        elem = it->getCurrent();
        frut = dynamic_cast <Fruta*> (elem); 
        frut->printFruta();
        it->next();
    }

    system("pause");
    



    return 0;
}

tasks.json

代码语言:javascript
运行
复制
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe compilar archivo activo",
            "command": "C:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "*.cpp",
                "-o",
                "${fileDirname}\\main.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Tarea generada por el depurador."
        }
    ],
    "version": "2.0.0"
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-03 06:17:28

如果您已经有一个带有调试信息(-g)的编译版本,则不需要再次包含头文件。

只需从配置中删除行"preLaunchTask":"C/C++:g++.exe compilar archivo activo“,因为您的程序已经编译。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68231069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档