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!