Visual studio code configuration C, C + + environment / compile and run process analysis


Overall process:

Download and install vscode
Install cpptools plug-in
Installation, compilation and debugging environment
Modify vscode debug configuration file
Download and install vscode  

Install cpptools plug-in

Open vscode, press Ctrl + P to open the quick command box, enter the following command and wait

ext install cpptools

Vscode will list a list of plug-ins after a short online search, as shown in the following figure:


Click the button indicated by the arrow to install the plug-in. The installation process may be slow and patient
After the installation, vscode will prompt you to restart vscode, and then restart it

Installation, compilation and debugging environment

(if CodeBlocks, dev, C + + etc. are installed on the computer, you can skip this step,

Directly jump to [configure system environment variable path])

At present, only cygwin and MinGW are supported in Windows downgrading.
MinGW is used here
The following is the installation and configuration process of MinGW:  
Enter the official website and click download installer on the right to download the installer
Open the installer and click Install to prepare for installation


Select an installation directory. The default value is C: MinGW. Here, you select a: MinGW
Click continue to start the installation. The installation process needs to be connected to the network. If an error is prompted during installation, you need to cross the wall
The installation process is very fast. After the end of the installation, the Continue button will return to the available state. Click finish installation.


Open the MinGW installation manager for further configuration


Note that GDB must be selected here, otherwise it cannot be debugged


Select several required items and right-click make for installation to mark. GCC and G + + are C and C + + compilers
After selecting all the items you want to install, click apply changes under the installation menu in the upper left corner to apply the modification. The process needs to be connected to the network. If there is an error in the middle, you can continue first. If it fails at last, you need to go over the wall and update it. It is recommended to cross the wall.

[configure system environment variable path]

Then configure the system environment variable path, which is required
Right click Properties on my computer:
Then follow the steps below. Note that the newly-built item should correspond to the previous installation position of MinGW

Windows 7 attention, to join, not overlay! I accidentally covered the original path for the first time… Because win7 is not as obvious as win10


After you restart the system, open the vscode environment variable again
Note that vscode debugging needs to be done in the open folder (note! Open folder with VSC!! , open a separate CPP separately is not the following configuration files appear!! In other words, the CPP should be in a folder! Unlike devcpp and C-free, you can debug a single CPP directly

After opening the folder, create a new test.cpp Input code test:


Enter the debugging interface as shown in the figure and select c + +:


It will then generate one in the working directory launch.json Start profile for:


Replace the file with the following code: (just add some lines to the JSON file generated by VSC itself)

launch.json If you want to set a lot of properties, you can view them by hovering

    "version": "0.2.0", 
    "configurations": [ 
        "Name": "(GDB) launch", // configuration name, which will be displayed in the drop-down menu of startup configuration 
        "Type": "cppdbg", // configuration type, here can only be cppdbg 
        "Request" or "launch" can be configured 
        "Program": "${workspaceroot} / ${filebasenamenoextension}. Exe", // the path of the program to be debugged 
        "Args": [], // the command line parameter passed to the program during program debugging is generally set to null 
        "Stopatentry": false, // when set to true, the program will pause at the program entrance, generally set to false 
        "CWD": "${workspaceroot}", // the working directory for debugging programs. Generally, ${workspaceroot} is the directory where the code is located 
        "environment": [], 
        "Externalconsole": true, // whether the console window is displayed during debugging. Generally, it is set to true to display the console 
        "MIMode": "gdb", 
        "miDebuggerPath": "C:\Program Files (x86)\CodeBlocks\MinGW\bin\ gdb.exe ", // the path of midebuggerer. Note that it should correspond to the path of MinGW 
        "Prelaunchtask": "G + +" // a task executed before the start of a debugging session. It is usually a compiler. C + + is G + +, C is GCC 
        "setupCommands": [ 
            "description": "Enable pretty-printing for gdb", 
            "text": "-enable-pretty-printing", 
            "ignoreFailures": true 

Note that midebuggerpath should correspond to the path of MinGW

Save after replacement and switch to test.cpp Press F5 to debug. A message box will pop up asking you to configure the task to run the program and click it~


Choose one or others here:


Then replace it with the following code:

    "version": "0.1.0",
    "command": "g++",
    "Args": ["- G", "${file}", "- O", "${filebasenamenoextension}. Exe"], // compile command parameters
    "problemMatcher": {
      "owner": "cpp",
      "fileLocation": ["relative", "${workspaceRoot}"],
      "pattern": {
        "regexp": "^(.*):(\d+):(\d+):\s+(warning|error):\s+(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "severity": 4,
        "message": 5

Save it and switch to test.cpp Press F5 again to start debugging~


Configuration C_ cpp_ properties.json
In the editor, there is a problem with the code. Take a look at “include”. There is a light bulb on the left. Click it to jump out of the configuration file. Modify the “includepath” of the Win32 as follows. As above, adjust it according to your own path. After testing, the registration part of the code in the figure below is still necessary

    "name": "Win32",
    "includePath": [
      "C:/Program Files/MinGW/include/*",
      "C:/Program Files/MinGW/lib/gcc/mingw32/5.3.0/include/*"
    "browse": {
      "limitSymbolsToIncludedHeaders": true,
      "databaseFilename": ""


Once and for all: since vs needs to be configured separately for each folder, it is recommended to put the. Vscode folder at the top of your commonly used folder so that you don’t have to repeatedly configure it.
It is not necessary to have a set of configuration for each new cpp file. These configurations are available for all subfolders and files in your configured folder.


Final effect:

Set breakpoints, variable monitoring, call stack view:


Use of conditional breakpoints:


Because vscode does not support debugging Chinese named files, it is better not to use Chinese named files


This article on the visual studio code configuration C, C + + environment / compile and run process analysis article introduced here, more related vscode configuration C, C + + environment compile and run content, please search the previous articles of developeppaer or continue to browse the following related articles, hope that you can support developeppaer more in the future!

Recommended Today

Webassembly and trust

Rust’s support for webassembly is the most perfect. After all, a large part of Mozilla’s original development of trust was to write servo (browser rendering engine). In addition, the two wasm runtimes, wasmer and wasmtime, which we introduced, are also written with rust. For the use of rust to write wasm module and the use […]