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.
I personally feel that mingw is simpler. But the prerequisite is to install mingw.
Configure environment variables. Path environment variable
Install mingw. mingw64
My installation path is:
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.
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
delete other files
Vscode opens the folder test_mingw on behalf of
Press F5 directly to select GDB
Choose g++.
cpp.exe is the preprocessor, g++/gcc.exe is the compiler, gdb is the debugger