Detailed tutorial on the installation of vscode under unbantu, the configuration of the c++ environment and the visual code tracking and debugging

Installation of vscode under unbantu, detailed tutorial on configuration of C++ environment, and visual code tracking and debugging

I. Introduction

"People rely on clothes, horses and saddles, and dogs run with bells." Based on the command line tool gdb debugging in the previous job, practice using various visual debugging front-end software (the back-end still relies on gcc and gdb) to track and check the program code to improve work efficiency.

Tool: Based on the cross-platform multi-type code editor VScode.

2. Introduction to Tools

About VSCode:
      VSCode stands for Visual Studio Code. It is a lightweight code editor from Microsoft, free, open source and powerful. It supports syntax highlighting, smart code completion, custom hotkeys, bracket matching, code snippets, code comparison Diff, GIT and other features of almost all mainstream programming languages, supports plug-in extensions, and is designed for web development and cloud application development.了Optimized. The software supports Win, Mac and Linux across platforms. For it, writing MarkDown is a piece of cake. You may ask, I have so many special software to write MarkDown to choose from, just like the blogger recommends to write in the MarkDown editor, online, local, mobile, computer, countless, dry Why find an editor that writes code to do this. Because the blogger is setting up a game, not only do I want to introduce you to MarkDown, a particularly simple markup language, but I also want to introduce more things, such as R, LaTex, Python, AutoHotKey, etc. You have learned Will benefit a lifetime. And every time you open a new series, you have to introduce an easy-to-use editor. With so many series, it is too inefficient. It does not conform to the original intention of building a website. You don’t like to change the software every time you learn a new thing. Let's learn, so it's better to come to an "N in One". There are many "N in One" software, such as VIm, Emacs, Atom, etc., and VSCode is the software I recommend you to learn at this stage. why? In addition to the advantages introduced in the introduction to VSCode in the previous section, the other reason I chose it is that it is beautiful (the blogger is a beauty control), and it is quick to open large files. Below is a screenshot of the blogger's VSCode Linux version

3. Tool installation

Method 1: Graphical installation (not detailed here), please refer to: link: https://www.cnblogs.com/lwp-king666/p/10513382.html .
Method 2: Command installation: as follows
#### 1) Direct Download in unbantu's firxbox browser
. Download the latest version from vscode official website, deb package download address: link: https://code.visualstudio.com/docs?dv=linux64 .
Insert picture description here

2) Installation: dpkg -i installation package

Pay attention to the location of the installation package

sudo dpkg -i code_1.50.1-1602600906_amd64.deb

Insert picture description here

3) After the installation is successful, execute the code command to open the vscode interface

Insert picture description here
The installation is complete

4) If something goes wrong

Re-install sudo dpkg -i installation package

Four. About compiling and debugging C\C++ with vscode in ubuntu

1. Quick build based on plugin

Prerequisite: You must have gcc/g++ compiler and gdb debugger under Linux

Enter gcc -v and g++ -v to check the gcc/g++ environment, and enter gdb -v to check the gdb environment. If
not, use
sudo apt-get install gcc sudo apt-get install g++
and
sudo apt-get install gdb

1) Install the C\C++ and Chinese plug-ins of vscode.

We open the extension store directly in the left menu, search directly, enter c++ and press Enter, the following tools will appear, we install the following two
Insert picture description here

Insert picture description here

Insert picture description here
Similarly, we directly open the extension store in the left menu, directly search for Chinese and press Enter, the following tools will appear, we install simplified Chinese, and restart vscode as prompted.
Insert picture description here

2) Write and write hellow.cpp test

Before that, we should create a working folder under home, take the name by ourselves, then open this folder in vscode, and then we directly create a new hellow.cpp test file under vscode
Debug code:

#include<iostream>
using namespace std;
int main(){
    
    
    cout<<"hello world!"<<endl;
    cout<<"nisha        ";
    return 0;
}

Insert picture description here

3) We use the second extension tool to run directly, we can run directly

Press F6 to run
Insert picture description here

2. Method two: traditional quick setup and use (extension tool one)

The traditional method is to configure, here for speed, only need to configure two files, launch.json and task.json, respectively tell vscode where to run the c++ program and how to generate and run the program

1) Start from scratch

From scratch, first there is only one source cpp file, nothing else
Insert picture description here

2) Try to compile and configure

We pretended to try to run by pressing F5, and found that vscode prompts us to choose a debug program, we choose gdb here (we found that it is not running)

Insert picture description here
Select g++ to generate and debug active files
Insert picture description here
At this time, the system will automatically generate a configuration file, you return to the cpp file, F5 can run
Insert picture description here

Five. Program debugging

1) Set up the debugger

hello.cpp, this is another file I created. If we have debugged a program at the beginning, we must delete the previous .json file and add it again according to the previous debugging steps

#include<iostream>
using namespace std;
void ShowRevertNum(int iNum)
{
    
    
 while (iNum > 10)
 {
    
    
 iNum = iNum / 10;
 }
    cout<<iNum;
}
int main(void)
{
    
    
 int iNum;
 cout<<"Please input a number :";
 cin>>iNum;
 cout<<"After revert : ";
 ShowRevertNum(iNum);
}

2) Set a breakpoint

You can add or delete breakpoints with a mouse click in front of the line sequence
Insert picture description here

2) Start debugging

Press F5 to debug, select the third one on top, and run in single step
Insert picture description here
Enter the value of iNum

Insert picture description here
Continue to run, check the value of the variable in the debug console
Insert picture description here

Six. Summary

      The blogger here introduces you to the installation of vscode in the Linux environment, and shows you the process of configuring C++ in vscode, as well as simple GDB debugging. The blog here is mainly Amway, an easy-to-use software, really It's so awesome.

Guess you like

Origin blog.csdn.net/nsnsnbabsb/article/details/109535722