Reputation: 46
I recently moved to VSCode and im a little be lost.
If i compile my program with this console command
g++ -Wall -o main main.cpp src/*.cpp -I included
It compiles and generates the .exe file correctly.
But i have a bug in it, so i want to use the debugger to know what is happening. When i hit run -> star debuggin in VSCode i get a console message of "not such file or directory" for one of my included files. So, i think i have some wrong configuration in my launch.json
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": "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"
}
]
}
i do not relly underestand what should i put in args or environment
EDIT:
this is the error message
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.
and this is main.cpp
#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
{
"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"
}
Upvotes: 0
Views: 936
Reputation: 193
If you already have a compiled version with debug information (-g) then you do not need to include the header files again.
Just remove the line "preLaunchTask": "C/C++: g++.exe compilar archivo activo" from the configuration since your program is already compiled.
Upvotes: 1