Install VS Code in Ubuntu environment and configure C++ environment

introduction

On the company's new computer, it is necessary to install the new VS Code and configure the C++ related environment in the new ubuntu environment. Compared with the Win environment, it is easier to configure the environment in Ubuntu. The Ubuntu environment is 20.04, as shown in the figure below:

specific process

1. Install VS Code

1. Because it is installed in Ubuntu, just go to Ubuntu Software to search directly, click to install to install (wait for a short time), as shown in the figure below (the blogger has already installed it):

 2. After the installation is completed, enter the code in the terminal to open the VsCode software, as shown below:

 3. Install gcc, g++ and gdb respectively (installing these three in Ubuntu is very simple, just enter the following commands):

sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install gdb

 This step can be completed quickly, then enter the following command to verify whether the installation is successful (the picture below is a screenshot after the installation is successful):

gcc -v
g++ -v
gdb -v

 Two, configure the C++ environment

1. Install the C++ plug-in, click on the bottom four small squares and search for C++, and click install to download after entering (it has been downloaded in the map):

 2. Install the Runner plug-in. Just like above, click to download and install. It can be installed in a few seconds.

3. Configure the debug environment (after completing the above configuration, you can run normally. If you have any bugs, you can leave a message and the blogger will add it)

If you want the code to be able to debug, you need to create a new folder called .vscod, and prepare two files in the folder, one is launch.json, and the other is tasks.json. Only with these two can you debug normally, as shown below:

Among them, the content in launch.json is as follows, you can copy it directly:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false, // 打开这个会另起一个终端显示结果
            "MIMode": "gdb",
            "preLaunchTask": "compile",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

In the same way, the contents of the tasks.json file are as follows, you can also copy them directly:

{
    "version": "2.0.0",
    "tasks": [{
            "label": "compile",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

 After completing the above, you can perform debugging operations.

Like it, dear!

Guess you like

Origin blog.csdn.net/qq_39149619/article/details/131597314