VSCode1-configure C/C++ environment

➺➻➸ Main process:

1. Download VScode

2. Install the cpptools tool

3. Download MinGW

4. Configure environment variables

5. Use a simple .cpp file to configure the C++ environment

6. run

 

  ➺➻➸ Detailed interpretation:

1. Download VScode

Download link: https://code.visualstudio.com/Download

Installation process: one step at a time, the installation is very simple, the installation path depends on the individual

2. Install the cpptools tool

Open vscode and follow the steps below to install

3. Download MinGW

Download address: https://sourceforge.net/projects/mingw-w64/files/

Downloaded file: Do not click "Download Lasted Version" after entering the website, but scroll down to find the latest version of "x86_64-posix-seh".

Install MinGW: After downloading, it is a 7z compressed package. After decompressing, move it to the location you want to install. My installation location is: D:\2Software\mingw64

4. Configure environment variables

Configuration object: MinGW, so copy the path you just installed MinGW

Configure environment variables: Take win10 as an example here. After reaching step 6, press OK for the previously opened windows, otherwise it will fail.

[Note]: win7 needs to add the path, don't overwrite it. In case it is really covered, click cancel and start again, as long as you don’t click OK, you can say anything ^o^

  After configuring the environment variables, it is best to restart VScode ^V^

  ❁❁❁ Verify that the environment variables are configured successfully

Press win + R, enter cmd, enter g++ after the Enter key, and press Enter again. If the following information [1] is displayed, the environment variable configuration is successful. If the following information [2] is displayed, the environment variable configuration fails.

[1]:g++: fatal error: no input files

[2]: 'g++' is not recognized as an internal or external command, operable program or batch file.

5. Use a simple .cpp file to configure the C++ environment

  (1) Create a new empty folder Code

  (2) Open VScode --> Open Folder --> Select the folder Code just created

  (3) Create a new test.cpp file (take the simplest HelloWorld.cpp as an example)

copy code

#include <stdio.h>
#include <windows.h>
int main()
{
    printf("Hello World\n");
    system("pause");
    return 0;
}

copy code

  (4) Enter the debugging interface to add the configuration environment, select C++ (GDB/LLDB), and then select g++.exe, and then the launch.json configuration file will be automatically generated

  (5) Edit launch.json configuration file

copy code

 1 {
 2     "version": "0.2.0",
 3     "configurations": [
 4         {
 5             "name": "g++.exe build and debug active file",
 6             "type": "cppdbg",
 7             "request": "launch",
 8             "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
 9             "args": [],
10             "stopAtEntry": false,
11             "cwd": "${workspaceFolder}",
12             "environment": [],
13             "externalConsole": true,      //修改此项,让其弹出终端
14             "MIMode": "gdb",
15             "miDebuggerPath": "D:\\2Software\\mingw64\\bin\\gdb.exe",
16             "setupCommands": [
17                 {
18                     "description": "Enable pretty-printing for gdb",
19                     "text": "-enable-pretty-printing",
20                     "ignoreFailures": true
21                 }
22             ],
23             "preLaunchTask": "task g++" //修改此项
24         }
25     ]
26 }

copy code

  (6) Return to the .cpp file, press F5 to debug, it will pop up that the task "task g++" cannot be found, select "Configure Task", and the tasks.json file will be automatically generated

  (7) Edit tasks.json file

copy code

 1 {
 2     "version": "2.0.0",
 3     "tasks": [
 4         {
 5             "type": "shell",
 6             "label": "task g++",    //修改此项
 7             "command": "D:\\2Software\\mingw64\\bin\\g++.exe",
 8             "args": [
 9                 "-g",
10                 "${file}",
11                 "-o",
12                 "${fileDirname}\\${fileBasenameNoExtension}.exe"
13             ],
14             "options": {
15                 "cwd": "D:\\2Software\\mingw64\\bin"
16             },
17             "problemMatcher": [
18                 "$gcc"
19             ],
20             "group": "build"
21         }
22     ]
23 }

copy code

[Note]: The value of "preLaunchTask" in the launch.json file must be consistent with the value of "label" in the tasks.json file. The setting of the value depends on personal preference, and it is OK to keep the default.

6. run

  Return to the HelloWorld.cpp file, press F5 to debug, and find that it is completely OK!

 

Welcome to join the technical discussion group, no ads, pure technology, welcome all big guys, newbies are also welcome, discrimination against novices is prohibited in the group, big guys answer questions voluntarily.

Guess you like

Origin blog.csdn.net/dongyunlong123/article/details/110950100