6

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.

4
  • do you mean "launch.json"? Commented Sep 5, 2017 at 18:06
  • ohh yes, launch.json my bad. Commented 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. Commented Sep 7, 2017 at 0:17
  • using minGW. Can you show me the syntax of that, to add -g before compiling. Commented Sep 7, 2017 at 3:05

1 Answer 1

2

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"
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.