A minimalist method of vscode to build a c++ program development environment (windows system)

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
insert image description here

After decompressing it, put it anywhere on the hard disk, but the directory should not have a Chinese name.
insert image description here
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.
insert image description here

Install vscode related plugins

The simplest only need these four
insert image description here

Create a minimal project directory

Under the project directory, the simplest two files are main.cpp and CMakeLists.txt

insert image description here
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.
insert image description here

Commissioning project

At this point, just press insert image description herethe button at the bottom, and you can run the debug. Yes, it's that simple, you don't need a file like launch.json.
insert image description here

For more complex projects, you only need to write CMakeLists.txt.

Guess you like

Origin blog.csdn.net/flamebox/article/details/126197871