1. VSCode installation and C/C++ compilation plugin installation
1. Download the .deb file of VSCode and install it directly
2. Open VSCode, press Ctrl+P to start the command window, and then enter ext install, then the relevant C++ plug-ins will be listed on the far left, and you can choose to install them according to your actual needs, as shown in the following figure.
2. Compile the code
Since CSCode can only compile code in the form of a directory, when VSCode compiles the code of the specified project, it directly opens the directory corresponding to the project.
When compiling the code, you need to configure a task.json script file to describe the commands and parameters required for compilation, and then "Ctrl+Shift+B" to compile the project code.
- The creation and writing of task.json script.
1) Ctrl+Shift+B——>Click "Configure Generation Task" in the prompt message————>Use template to create task.json file——>other
Or in the menu bar "task"------->"run build task"------""configure build task"-------> use template to create task.json file - ——>other, the default task.json file is as follows:
2) Write (write format, follow the format of json)
lable: task name // take it by yourself, such as Build
commd: configure the compile command // such as: g++
You can also specify command parameters for compilation
args: [command parameters]
After completing this step, you can use Ctrl+Shift+B to compile the code and generate the object file.
3. Debug code
To debug the code, you need to generate a launch.json script file. Once generated, you can use the F5 shortcut key
1. Create launch.json file
Menu bar "Debug"---------->"Start Debug"------------->C++(GDB/LLD)
or F5------------->C++(GDB/LLD)
or the debug icon on the far left ---------> settings icon
The following file contents are created by default:
2. Edit the file content
program: configure the startup program to debug
args: input parameters of the configuration program
stopAtEntry: whether to re-entry function breakpoint //true: the breakpoint will be at the main function
MIMODE: debugging tools // such as gdb