Visual studio code configuration C + + development environment tutorial detailed explanation (Windows development environment)

Time:2021-4-19

0 Introduction

Recently, I helped GF (unfortunately, it became Ex) to configure the C + + development environment. At first, I wanted to install visual studio 13 for her. However, when I thought about the troubles in installing and using it, I retreated a little and didn’t think it was necessary. Just knowing that vscode is popular, I decided to configure a version according to the instructions of the official website. Because I’m not a computer major, I don’t know much about compiling principles. I encountered some troubles when configuring the environment. Referring to many online tutorials, I finally found that the official website is more reliable. So I wrote a post based on my own configuration lessons, hoping to help you.

1 download and install vscode

The download URL is as follows.

https://code.visualstudio.com/

Download and install it directly.

2 configuration language

1) Shift + Ctrl + P, open the command line.

2) Enter “configure display language” in the input box and click open locale.json .

3) Editor locale.json File, as shown in the figure. “Locale”: save “zh CN”, and then reopen the editor.

3 install C / C + + related plug-ins, including the following plug-ins.

1)C/C++

2)C++ Intellisense

3) Chinese (Simplified) simplified Chinese

4 install C + + compiler

Choose to install tdm64-gcc-5.1.0-2.exe. The download URL is as follows.

https://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-5.1.0-2.exe/download

If the above address fails, enter http://tdm-gcc.tdragon.net/download , choose the second one. It is recommended to install it directly on Disk C to reduce the trouble of modifying the path later. During installation, you need to manually check the option (GDB) as shown in the figure below. Otherwise, the following 5 options are not available launch.json “

“miDebuggerPath”: “C:/TDM-GCC-64/bin/gdb64.exe”

There will be mistakes.

5 configuration programming environment

Configure four. JSON files, refer to the official practice

https://code.visualstudio.com/docs/languages/cpp

1) Create a new folder, such as myvscodeproject. Open the folder in vscode and create a new. Cpp file.

2) Click “debug” (Ctrl + Shift + D) – “add configuration” – “select c + + (GDB / lldb), the system willmyVsCodeProjectAutomatically generate a folder launch.json Documents.

You need to be rightmiDebuggerPathTo be amended as follows:

“miDebuggerPath”: “C:/TDM-GCC-64/bin/gdb64.exe”

After revision, launch.json In this way, you can directly copy this part of the content to the reader’s corresponding file.

{
 //Use IntelliSense to understand related properties. 
 //Hover to see a description of an existing property.
 //For more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387
 "version": "0.2.0",
 "configurations": [
 
 {
 "name": "(gdb) Launch",
 "type": "cppdbg",
 "request": "launch",
 "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
 "args": [],
 "stopAtEntry": false,
 "cwd": "${workspaceFolder}",
 "environment": [],
 "externalConsole": true,
 "MIMode": "gdb",
 "miDebuggerPath": "C:/TDM-GCC-64/bin/gdb64.exe",
 "setupCommands": [
 {
  "description": "Enable pretty-printing for gdb",
  "text": "-enable-pretty-printing",
  "ignoreFailures": true
 }
 ],
 "preLaunchTask": "build"
 }
 ]
}

After revision,c_cpp_properties.jsonThe content of is as follows. You can add the path of your own external link library.

3) CTRL + Shift + P – “C / CPP: edit configurations”c_cpp_properties.json The document needs to be modified in two places. namely:


“includePath”:[
"${workspaceFolder}/**",
"C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++",
"C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32",
"C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward",
"C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
"C:/TDM-GCC-64/x86_64-w64-mingw32/include",
"C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include-fixed"
]

and

“compilerPath”: “C:/TDM-GCC-64/bin/g++.exe”

After revision,c_cpp_properties.jsonThe content of is as follows. You can add the path of your own external link library.


{
 "configurations": [
 {
 "name": "Win32",
 "includePath": [
 "${workspaceFolder}/**",
 "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++",
 "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32",
 "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward",
 "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
 "C:/TDM-GCC-64/x86_64-w64-mingw32/include",
 "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include-fixed",
 "D:/Random/include"
 ],
 "defines": [
 "_DEBUG",
 "UNICODE",
 "_UNICODE"
 ],
 "windowsSdkVersion": "8.1",
 "compilerPath": "C:/TDM-GCC-64/bin/g++.exe",
 "cStandard": "c11",
 "cppStandard": "c++11",
 "intelliSenseMode": "msvc-x64"
 }
 ],
 "version": 4
}

4)Ctrl+Shift+P -》Tasks: Configure Tasks -》Create tasks.json Modify the file from templates as follows:

“command”: “g++”

and

"args":[
"-g" ,"${fileBasename}",
"- fexec charset = GBK", // console form output character encoding to ensure normal display of Chinese
"- find put charset = UTF-8" // enter the compiler text encoding. The default is UTF-8
]

In order to use the new features of C + +, add the following statement to “args”:

“- STD = C + + 17” / / use the latest C + + 17 standard

To be able to run on other machines, add the following statement to “args”:

“- static libgcc”, / / static link

After modification, it looks like this.

{
 // See https://go.microsoft.com/fwlink/?LinkId=733558
 // for the documentation about the tasks.json format
 "version": "2.0.0",
 "tasks": [
 {
 "label": "build",
 "type": "shell",
 "command": "g++",
 "args":[
 "-g" ,"${workspaceFolder}/${fileBasename}",
 "- I", "D / random / include" // the address of the external library used in compilation
 "- O", "${workspacefolder} / ${filebasenamenoextension}. Exe", // specify the output file name, without this parameter, a.exe will be output by default
 "- ggdb3", // information about generation and debugging
 "- wall", // turn on extra warning
 "- static libgcc", // static link
 "- STD = C + + 11" // use the latest C + + 17 standard
 "-Wno-format",
 "- fexec charset = GBK", // console form output character encoding to ensure normal display of Chinese
 "- find put charset = UTF-8" // enter the compiler text encoding. The default is UTF-8  
 ],
 "group": {
 "kind": "build",
 "isDefault": true
 }
 }
 ]
}

5) Debug debugging to run, enjoy!

6 detailed description of configuration file function

You can refer to my another article

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

summary

This article about visual studio code configuration C + + development environment tutorial detailed explanation (Windows development environment) is introduced here. For more related visual studio code configuration C + + content, please search previous articles of developer or continue to browse the following related articles. I hope you can support developer more in the future!

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]