vscode C + + program windows

vscode 1.42.1
OS: windows 7 x64

1. vscode, cpp extension

This article directly skips vscode installation and Cpp tools installation

2. MinGw installation and configuration

download MinGW - Minimalist GNU for Windows

setup script

Installation dependent environment

3. Configure environment variables

4. debugging

Configure launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,  // Change to true here
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++"
        }
    ]
}

Configure task.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "g++",
            "type": "shell",
            "command": "D:\\MinGW\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            
            "options": {
                "cwd": "D:\\MinGW\\bin"
            },
            
            "problemMatcher": [
                "$gcc"
            ],

            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "new",
                "showReuseMessage": true,  //Here, shared means shared. After changing to new, each process creates a new port
                "clear": false
            }
        }
    ]
}

Final result

Reference resources

  1. Organize: Visual Studio Code (vscode) configure C, C + + environment / write and run C, C + + (main Windows, brief Linux)
  2. Basic knowledge of vscode and how to configure C + + Environment
  3. On the solution of VScode error reporting "terminal will be reused by task and closed by pressing any key"
  4. VSCode code debugger
  5. Compiling, running and debugging C/C with vscode on windows 10++
    Certainty of death. Small chance of success.

Tags: C++ Windows JSON shell Linux

Posted on Tue, 17 Mar 2020 11:41:42 -0400 by dannyd