Anyone using Visual studio code for programming in C++? Please tell me how can i manage to do the debugging of my code in visual studio code when I'm compiling it using g++ compiler.
-
do you mean "launch.json"?Basya– Basya2017-09-05 18:06:47 +00:00Commented Sep 5, 2017 at 18:06
-
ohh yes, launch.json my bad.Desmond– Desmond2017-09-05 18:07:37 +00:00Commented Sep 5, 2017 at 18:07
-
Are you using Cygwin, MinGW, or WSL? If you are using WSL, you can find more information here: github.com/Microsoft/vscode-cpptools/blob/master/Documentation/… In your tasks.json, make sure to compile with the -g flag for symbols.Warden– Warden2017-09-07 00:17:27 +00:00Commented Sep 7, 2017 at 0:17
-
using minGW. Can you show me the syntax of that, to add -g before compiling.Desmond– Desmond2017-09-07 03:05:52 +00:00Commented Sep 7, 2017 at 3:05
Add a comment
|
1 Answer
For debugging multiple cpp files inside the project directory.
Your launch.json and task.json should look like this
tasks.json
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
launch.json
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}