[VsCode] Use MINGW's g++.exe to compile C++ files and configure the environment.

0. Introduction: We all know that vscode is a great "editor", but I want to compile C++ and generate an executable file exe. Still need to configure the environment.

Solution 1: Use g++.exe in mingw to compile.

Solution 2: Use cl.exe in msvc to compile.

Solution 2, the following article has been configured.

(39 messages) [VsCode] Use MSVC's cl.exe to compile C++ files and configure the environment. _pull_future's Blog - CSDN Blog

I personally feel that mingw is simpler. But the prerequisite is to install mingw.

  1. Configure environment variables. Path environment variable

  1. Install mingw. mingw64

  1. My installation path is:

  1. There is also a mingw here. The difference between him and mingw64 is the same as Baidu. In fact, he is an installation program such as g++.exe and other gnu packages under mingw64.

  1. The main use is the path under mingw64, and the environment variable is added.

2. Test

Open cmd to see the g++ version, indicating that the environment configuration is successful.

Compile the cpp file

#include <iostream>
using namespace std;
int main()
{

for (int i = 0; i < 10; i++)
{
        cout<< "hello mingw g++"<<endl;
}

getchar();
    return 0;
}

run a.exe

3. Vscode test

  1. delete other files

  1. Vscode opens the folder test_mingw on behalf of

  1. Press F5 directly to select GDB

Choose g++.

cpp.exe is the preprocessor, g++/gcc.exe is the compiler, gdb is the debugger

Guess you like

Origin blog.csdn.net/m0_57168310/article/details/129234097