Build the vscode environment
Reference:
https://blog.csdn.net/moshiyaofei/article/details/103183742
https://blog.csdn.net/iningwei/article/details/101649090
vscode c++ installation
Also installed this
mingw64 installation
Software download
http://mingw-w64.org/doku.php/download
Specific settings:
after the installation is complete, you need to add \bin to the system environment variables
Confirm whether the installation is successful:
Build the compilation environment
ctrl+shift+p to open the window and select C++ edit
c_cpp_properties.json to start the configuration.
Here you have to enter the installation path yourself.
Select gcc to not report an error.
Create a build task. Press the shortcut key Ctrl+Shift+P in vs code, then Input: task
and then vs code will create tasks.json in the subfolder .vscode under the project folder.
Replace the code as follows
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": ["-g", "-o", "helloworld", "helloworld.cpp"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Among them, the meaning of each field in this code:
command:表示用当前项目使用g++.exe去编译它,
args:表示传到g++中的命令行参数,
label:表示在VS Code Command Palette中显示的名称,可以自己定义喜欢的,
isDefault": true,是为了快捷编译设置的,如果设置为true,那么可以使用Ctrl+Shift+B这个快捷键来编译代码,如果设置为false,那么你必须使用Command Palette 菜单栏下的Run Build Task这个命令来编译它,如下图所示,可以看到Run Build Task这个命令后面有一个Ctrl+Shift+B这个快捷键,就是说明如果在tasks.json文件中设置了isDefault": true的话,你可以使用Ctrl+Shift+B快捷键快速编译代码。
Next, configure the Debug settings. First use Ctrl+Shift+P to open the Command Palette, and then enter launch
to see the configuration in launch.json. The meanings of these fields are as follows:
program:这个字段的值使用helloworld.exe替换默认的program的值,这儿的值和tasks.json文件中设置的名称要一样。
miDebuggerPath:这个字段的值要使用Mingw-w64安装路径心中bin目录下的gdb.exe的路径,我的是: E:\mingw\az\mingw64\bin\gdb.exe
stopAtEntry:C++ extension会在main函数的第一行添加一个断点,stopAtEntry这个字段的值表示是否要让debugger 执行时停留在这个断点,如果设置为true,则debugger执行时会停留在这个断点,如果设置为false,那么debugger执行时不会停留在这个断点。
externalConsole:这个字段设置为true表示在外部控制台中运行程序。
The configured launch.json file is shown in the figure below. When setting the path of miDebuggerPath, you need to "add escape characters", otherwise an error will occur:
Next is the encoding source file, create a new helloworld.cpp file, add code and save.
ctrl+shift+b compile.
Step on the pit
Restart mingw64 after installing vscode, otherwise the project will fail to compile.