4806 views|2 replies

654

Posts

26

Resources
The OP
 

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

链接已隐藏,如需查看请登录或者注册

链接已隐藏,如需查看请登录或者注册

This post is from Innovation Lab

Latest reply

d   Details Published on 2022-3-21 13:39
Personal signatureQQ:252669569
 
 

1w

Posts

204

Resources
From 3
 

d

This post is from Innovation Lab
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

玩板看这里:

https://bbs.eeworld.com.cn/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 
 

7462

Posts

2

Resources
2
 

Thanks for sharing. There are not many complete posts about using vscode to do c/c++ under linux.

This post is from Innovation Lab
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list