17 "Ten Thousand Miles" Raspberry Pi Car——VSCode Learning (Compiling and Debugging)
[Copy link]
I've been programming in C++ recently, and I'm increasingly aware of the importance of having an IDE. Fortunately, I can use VSCode on the Raspberry Pi system. This software is much more complicated than the Geany introduced earlier, but it also has many more functions.
For a tutorial on using VSCode on Linux, please refer to the official website's tutorial, Get Started with C++ on Linux in Visual Studio Code .
VSCode Installation
In the Raspberry Pi system, go to "Start -> Preferences -> Recommended Software" and there are software recommended by the Raspberry Pi system. Check VSCode and click Apply to install it automatically.
Compile and run
Select "Add Folder" and then select an empty folder so that VSCode creates a workspace.
Click the New File button to create a new file called "helloworld.cpp".
Write the following code.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
Press the triangle in the upper right corner of the software to compile and run the code directly, which is the same as the previous compilation and running using the Geany software.
Debugging Code
Select "Run->Add Configuration" in the main menu, then the option to select the environment pops up, select "C++(GDB/LLDB)",
Next, you will be automatically asked to select the configuration option. Select "g++ generate and debug active files", and all the settings are completed.
The software will automatically generate tasks.json and launch.json. One of these two files is responsible for compilation settings, and the other is responsible for debugging settings. We will not worry about the contents of the files for now.
The official website requires you to select the configuration first and then the environment. This is not a good idea as it will add many more steps and the generated files will need to be modified.
Operation Results
Press F5 to enter the debugging mode, where you can set breakpoints, single-step debugging, view variables, and so on.
Tips
If you want to close the current workspace, you can right-click on the current workspace file and select Delete Folder from Workspace. Similarly, if you want to import a new workspace, just open the folder where ".vscode" is located.
question
The variable value must be paused before it can be viewed. How can I run a real-time preview of global variables like Keil and IAR?
Source code
|