Methods and steps of configuring C + + development environment with vscode

Time:2021-4-21

The first step is to install the vscode application

Open the official website of vscode, download the corresponding installation package and install it by default ( Here: the installation path can be modified )

The second step is to install related plug-ins

At this time, vscode is only an English text editor, which is not a development tool, so it needs the support of related plug-ins.

It should be noted that: Here I choose my native language as the language of the editor, so I will install one more Chinese plug-in!

Install Chinese plug-in

Open vscode, enter “Chinese” in the plug-in search input box, and search the plug-in “Chinese (Simplified) language pack for visual studio code”. clickinstallInstall the plug-in.

Install C + + editor plug-in

Enter “C + +” in the plug-in search input box to search the plug-in “C / C + + for visual studio code”. clickinstallInstall the plug-in.

The third step is to write configuration file

At this point is just barely a development tool, but still need further configuration!

Prerequisite note: the C + + compiler environment has been installed and configured by default! If necessary, please see the appendix — C / C + + compiler environment configuration

Create a new folder where you write your code and name it “. Vscode”. Then create three new files in the “. Vscode” folder, which are:

1. tasks.json
2. launch.json
3. c_cpp_properties.json

reference resources:

to write tasks.json file

This file tells vs code how to build (compile) the program.

{
  "version": "2.0.0",
  "command": "g++",
  "args": [
    "-g",
    "${file}",
    "-o",
    "${fileBasenameNoExtension}.exe"
  ], // compile command parameters
  "problemMatcher": {
    "owner": "cpp",
    "fileLocation": [
      "relative",
      "${workspaceFolder}"
    ],
    "pattern": {
      "regexp": "^(.*):(\d+):(\d+):\s+(warning|error):\s+(.*)$",
      "file": 1,
      "line": 2,
      "column": 3,
      "severity": 4,
      "message": 5
    }
  }
}

Editor launch.json file

This file is responsible for configuring vs code.

{
  "version": "0.2.0",
  "configurations": [
    {
      "Name": "(GDB) launch", // configuration name, which will be displayed in the drop-down menu of startup configuration
      " type ": " cppdbg ", //  The configuration type can only be cppdbg
      "Request": "launch", // request configuration type, which can be launch or attach
      "Program": "${workspacefolder} / ${filebasenamenoextension}. Exe" // the path of the program to be debugged
      "Args": [] the command line parameter passed to the program during program debugging. Generally, it can be set to null
      "Stopatentry": false, // when set to true, the program will pause at the program entrance, generally set to false
      "CWD": "${workspacefolder}" // when debugging a program, the working directory is generally ${workspaceroot}, that is, the directory where the code is located. Workspaceroot has been abandoned and is now changed to workspacefolder
      "environment": [],
      "Externalconsole": true, // whether to display the console window during debugging. Generally, it is set to true to display the console
      "MIMode": "gdb",
      "miDebuggerPath": "E:\MinGW\bin\ gdb.exe "// the path of midebugger. Note that it should correspond to MinGW's path
      " preLaunchTask ": " g ++", //  The task to be performed before the start of a debugging session, usually a compiler, C ++ Is g ++,  C is GCC
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": false
        }
      ]
    }
  ]
}

Editor c_ cpp_ properties.json file

This file is used to further control C / C + + extensions. It will allow you to change settings such as compiler path, include path, C + + standard (default is C + + 17), etc.

Need to explain: this file is not necessary, can not!


{
  "configurations": [
    {
      "name": "Win32",
      "includePath": ["${workspaceFolder}/**"],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "compilerPath": "E:\MinGW\bin\gcc.exe",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "clang-x86"
    }
  ],
  "version": 4
}

appendix

c_ cpp_ properties.json How to get the path of includepath in file

Open the CMD command line tool and entergcc -v -E -x c++ -

Note: the first line of the includepath is the include folder in the root directory of MinGW.

C / C + + compiler environment configuration

   1. Download the installation program from MinGW official website, and install by default.
   note: the installation path can be modified.
   2. After the installation, start the program and install the basic library file.

reference resources:

   3. In the system (or user) environment variable path, add the bin folder path under the installation root directory of MinGW, for example: e:: (MinGW)   3
   4. Input in the CMD command line toolgcc -vCheck to see if the installation is successful.

Reference article

Introduction to C + + and mingw-w64 in Visual Studio code

Copyright notice

Author: Seaver
If you want to reprint, please be sure to indicate the source!
Original address: https://www.cnblogs.com/seafever/p/12571272.html

Here is the article about vscode configuration of C + + development environment. For more information about vscode configuration of C + + development environment, please search previous articles of developer or continue to browse the following articles. I hope you can support developer more in the future!

Recommended Today

Deeply analyze the principle and practice of RSA key

1、 Preface After experiencing many dark moments in life, when you read this article, you will regret and even be angry: why didn’t you write this article earlier?! Your darkest moments include: 1. Your project needs to be connected with the bank, and the other party needs you to provide an encryption certificate. You have […]