Install and configure the C / C + + development environment of vscode under Ubuntu 20.04

Time:2020-11-1

preface:

I installed Ubuntu 18.04 before. As a result, there were a lot of errors when installing CodeBlocks / vscode or GCC, C / C + + (missing dependency tree and other problems, and changing the source could not succeed). I didn’t make any progress all afternoon. I couldn’t find any solution on the Internet, so I had to reload Ubuntu After that, CodeBlocks was successfully installed. However, when the C / C + + and gcc compiler packages have been installed, it still shows that it can not be found in this path. No matter whether the path is automatically located under / usr or / usr / bin by default, this situation still occurs. Similarly, no solution can be found on the Internet, so we can only give up CodeBlocks and choose vscode (because CodeBlocks is always used in windows, so I stick to it). Fortunately, vscode finally works

在这里插入图片描述

Zero, the choice of Ubuntu image file

Ubuntu website

在这里插入图片描述

VMware Ubuntu installation tutorial

1、 Install vscode

Open the app store, search for vscode, enter the password, and wait for the installation to complete

在这里插入图片描述

Reference: configure the C / C + + development environment of vscode under Ubuntu 16.04
https://www.jb51.net/article/183733.htm

2、 Configure vscode environment

1. Open vscode, click extensions, search for C + + plug-in installation

在这里插入图片描述

2. Create a new folder in any directory (vscode manages project files through the folder), for example, I create it directly on the desktop

在这里插入图片描述

3. Open the folder in vscode

在这里插入图片描述

4. Establish new documents in it main.cpp , open main.cpp Press F5 or click Run > starting debugging to pop up the box for selecting environment. Select c + +, and select the first G + + (it doesn’t matter, anyway, the configuration file will be replaced directly)

在这里插入图片描述
在这里插入图片描述

5. It will be generated automatically after the previous step launch.json If not, click F5 again. open launch.json , replace all the files generated by default with the following:


{
 // Use IntelliSense to learn about possible attributes.
 // Hover to view descriptions of existing attributes.
 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 "version": "0.2.0",
 "configurations": [
 {
 "name": "(gdb) Launch",
 "type": "cppdbg",
 "request": "launch",
 "program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
 "args": [],
 "stopAtEntry": false,
 "cwd": "${workspaceFolder}",
 "environment": [],
 "externalConsole": true,
 "MIMode": "gdb",
 "preLaunchTask": "build",
 "setupCommands": [
 {
  "description": "Enable pretty-printing for gdb",
  "text": "-enable-pretty-printing",
  "ignoreFailures": true
 }
 ]
 }
 ]
}

6. Modification completed launch.json After the file, press F5 again. This time, a prompt will appear:

“No task to run found. configure tasks…”

Then select

Create tasks.json file from template

Others Example to run an arbitrary external command.

open task.json After that, replace all the default generated files with the following:


{
 // See https://go.microsoft.com/fwlink/?LinkId=733558
 // for the documentation about the tasks.json format
 "version": "2.0.0",
 "tasks": [
 {
 "label": "build",
 "type": "shell",
 "command": "g++",
 "args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
 }
 ]
}

3、 Complete the configuration, hello world!

Press F5, the output “Hello world” will be displayed in the terminal, so far the configuration work is completed!

在这里插入图片描述

summary

This article introduces the C / C + + development environment (text tutorial) of installing and configuring vscode under Ubuntu 20.04. For more information about the C / C + + development environment for installing and configuring vscode in Ubuntu, please search the previous articles of developeppaer or continue to browse the related articles below. I hope you can support developeppaer more in the future!

Recommended Today

Construction of Vue development environment and project creation under mac

start First of all, let’s take a look at the overall development environment of Vue. Homebrew: package manager under MAC system, similar to apt get under Linux, windows control panel – install and remove program Node.jsJavaScript runtime, which is similar to simultaneous interpretation in international conferences, can’t run various programming languages directly between different systems […]