There are still some problems with the details I wrote earlier – 2020.7.3 more
I studied from afternoon to 11:00 p.m. yesterday and consulted a lot of blog materials, but I still failed to configure the C++ compilation environment of vscode. I did it again this morning and it is OK now.
Although the principle of a lot of things does not understand, but now know so go, should be familiar with slowly with much later.
The first step is to download vscode from the official website. Install it in the position you want.
Vscode official portal
Step two, go to the official website to download MinGW. Install it in the position you want.
MinGW official portal
Do not click on the site after entering it"Download Lasted Version"
Go down and find itThe latest version
the"x86_64-posix-seh"
Download.
Third, configure the MinGW environment variable.
1. Copy the MinGW path (see point 6).
2. Open the Control Panel, search for advanced system Settings, and enter.
3. Click environment Variables.
4. Double-click Path.
5. Click Create.
6. Paste the MinGW address.
7. Press OK to exit all the Windows that have been opened.
Now that the MinGW environment is configured, you can verify that the configuration is successful :(if it fails, make sure the steps are correct and try again)
- Press Win + R, the run window appears, enter
cmd
- If I type g++, press enter, I’ll get two responses
Type 1: The environment is configured successfully
Second: The environment configuration fails
Tip: ‘g++’ is not an internal or external command, nor is it a runnable program or batch file.
Step 4, open vscode, click on the extension, download a Chinese package first.
Keep searching in the extensionC/C++
Plug-in and download
Step 6: Create a new one in the location you wantcode_test
Folder. Then open vscode and open this folder
incode_test
Create a new foldertest.cpp
file
intest.cpp
Enter a simple test code in the file:
#include <stdio.h> #include <windows.h> int main() { printf("Hello VScode! \nHello C++\n"); system("pause"); return 0; }Copy the code
Press CTRL +F5 and selectC++(GDB/LLDB)
, and selectg++.exe
.
When the above operations are complete, thelaunch.json
File, paste the code above and below:
(in addition to the"miDebuggerPath"
The path of MinGW needs to be changed, and other paths can be left unchanged.)
{// Use IntelliSense to learn about related attributes. // Hover to view descriptions of existing properties. / / for more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387 "version" : "0.2.0," "configurations: [{" name" : "G + +. Exe - generating and commissioning activities file", "type" : "CPPDBG", "request" : "launch", "the program" : "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true,// "MIMode": "GDB ", "miDebuggerPath": "D:\\2Software\\mingw64\ bin\ gdb.exe", "setupCommands": [{"description": "Enable neat printing for GDB ", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++.exe build active file" } ] }Copy the code
Go back totest.cpp
File, press CTRL +F5, the image below should appear, click Configure Task,
Automatically generatetasks.json
File, paste the following code:
{ "tasks": [ { "type": "shell", "label": "g++.exe build active file", "command": "D:\\2Software\\mingw64\\bin\\g++.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "D: \ \ software \ \ 2 mingw64 \ \ bin"}}], "version" : "2.0.0}"Copy the code