Record
foreword
Visual Studio is generally used to develop C++ programs under Windows, but this thing sometimes feels too heavy, so the lightweight vs code will be a good choice at this time. However, many articles on the Internet about vscode building a c++ development environment are more complicated, especially when configuring the gdb debugger. After some practice, I summed up a relatively simple construction method. Especially when configuring gdb, debugging can be realized without generating and configuring json files.
install mingw
Download mingw: https://github.com/niXman/mingw-builds-binaries/releases
I choose this here
After decompressing it, put it anywhere on the hard disk, but the directory should not have a Chinese name.
Add the path C:\mingw64\bin to the environment variable path, open the cmd window, and enter where g++
your file path, which means the configuration is correct.
Install vscode related plugins
The simplest only need these four
Create a minimal project directory
Under the project directory, the simplest two files are main.cpp and CMakeLists.txt
main.cpp content:
#include <iostream>
int main()
{
using namespace std;
int a = 20;
cout << "This is my first cpp program!" << endl;
a++;
cin.get();
return 0;
}
CMakeLists.txt content
cmake_minimum_required(VERSION 3.0)
project(APP)
add_executable(APP main.cpp)
vscode open project
Open the cmd window, switch to the project directory, and enter:
code .
Opening vscode will automatically build the project. At this time, click the execution icon and select the mingw tool chain, and the program can be automatically compiled and run.
Commissioning project
At this point, just press the button at the bottom, and you can run the debug. Yes, it's that simple, you don't need a file like launch.json.
For more complex projects, you only need to write CMakeLists.txt.