Vscode configuration of C / C + + compiling environment detailed text tutorial

Time:2020-11-16

Vscode C + + environment configuration

Step 1: Download and install

Download the mingw-w64 gcc-8.1.0 compiler for both 32 and 64 versions
Mingw-w64 GCC download address: https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/mingw-builds/installer/mingw-w64- install.exe
Offline download address: https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/
The installation option is x86_ 64-win32-seh

在这里插入图片描述
在这里插入图片描述

Step 2: environment configuration

Open your mingw-w64 installation directory. I installed it by default. In C: program files (x86), mingw-w64 is the compiler installed. Add the bin folder in the directory to the path. My is C: program files (x86) – mingw64 / bin

Add the path.

Path joining method:

在这里插入图片描述

After joining, it is recommended to restart the computer

The third step is to download and install vscode

  • Please download the latest version of vscode from the official website (64 bit version of recommended management rights)
  • Download address: https://code.visualstudio.com/#alt -downloads

在这里插入图片描述

Step 4: install vscode CPP related plug-ins

  • Vscode set up Chinese environment tutorial http://www.chuancn.cn/post/ Set vscode to Chinese language environment
  • C + + plug-in

在这里插入图片描述

-Restart vscode software

Step 5: configure the. Vscode file of C + +

  • Create a new folder where you write code and create a new folder in it
  • Then create a. Vscode folder in the folder

在这里插入图片描述

Then create the following four files in the. Vscode folder as shown in the figure above


c_cpp_properties.json
launch.json
tasks.json

Please modify the file path according to the installation location (if it is the same as me, do not change it)

launch.json

{
 "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": "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 is generally set to null
 "Stopatentry": false, // when set to true, the program will pause at the program entrance, generally set to false
 "CWD": "${workspacefolder}", // the working directory for debugging programs 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 the console window is displayed during debugging. Generally, it is set to true to display the console
 "MIMode": "gdb",
 "miDebuggerPath": "C:/Program Files (x86)/mingw64/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": false
 }
 ]
 }
 ]
}

tasks.json
If the file cannot be found, for example:

在这里插入图片描述

hold"${workspaceFolder}"Replace with"\\"or"//"

{
 "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
 }
 }
}

c_cpp_properties.json
“Includepath” sets the problem path to obtain the method: CMD — “gcc -v -E -x c++ -

gcc -v -E -x c++ -

If the first error occurs, use the second


{
 "configurations": [
 {
 "name": "Win32",
 "includePath": [
 "${workspaceRoot}",
 "C:/Program Files (x86)/mingw64/include/**",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
 ],
 "defines": [
 "_DEBUG",
 "UNICODE",
 "__GNUC__=6",
 "__cdecl=__attribute__((__cdecl__))"
 ],
 "intelliSenseMode": "msvc-x64",
 "browse": {
 "limitSymbolsToIncludedHeaders": true,
 "databaseFilename": "",
 "path": [
 "${workspaceRoot}",
 "C:/Program Files (x86)/mingw64/include/**",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
 ]
 }
 }
 ],
 "version": 4
}

The second kind


{
 "configurations": [
 {
 "name": "Win32",
 "includePath": [
 "C:/Program Files (x86)/mingw64/include/**",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
 "C:/Program Files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
 ],
 "browse": {
 "limitSymbolsToIncludedHeaders": true,
 "databaseFilename": ""
 }
 }
 ],
 "version": 4
}

Step 6: language configuration file of VSC

  • Create a new folder where you write code and create a new folder in it
  • Then create a. Vscode folder in the folder

在这里插入图片描述

  • Then create the following four files in the. Vscode folder as shown in the figure above
  • launch.json
  • tasks.json
  • launch.json
{
 "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": "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 is generally set to null
 "Stopatentry": false, // when set to true, the program will pause at the program entrance, generally set to false
 "CWD": "${workspacefolder}", // the working directory for debugging programs 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 the console window is displayed during debugging. Generally, it is set to true to display the console
 "MIMode": "gdb",
 "miDebuggerPath": "C:/Program Files (x86)/mingw64/bin/ gdb.exe ", // the path of midebuggerer. Note that it should correspond to the path of MinGW
 "Prelaunchtask": "GCC" // the task to be executed before the start of the 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": false
 }
 ]
 }
 ]
}

tasks.json


{
 "version": "2.0.0",
 "command": "gcc",
 "args": [
 "-g",
 "${file}",
 "-o",
 "${fileBasenameNoExtension}.exe"
 ]
}

Reference articles:

https://www.jb51.net/article/186531.htm

http://www.chuancn.cn/post/ Set vscode to Chinese language environment

summary

This article about vscode configuration C / C + + compiler environment detailed text tutorial article introduced here, more related vscode configuration C / C + + compilation environment content, please search the previous article of developeppaer or continue to browse the related articles below, hope that you can support developeppaer more in the future!

Recommended Today

Computer basic summary of 2021 autumn recruitment interview – operating system

A series of articles: 2021 autumn recruitment interview computer foundation summary – algorithm, data structure, design pattern, Linux Computer foundation summary of 2021 autumn recruitment interview – Java foundation, JVM, spring framework Computer foundation summary of 2021 autumn recruitment interview database, redis Computer basic summary of 2021 autumn recruitment interview – operating system Computer foundation […]