deppin下使用vscode编写C++

准备

需要一台安装Deppin系统的电脑

安装

直接在应用商店中下载(不多说)

img

开始配置

首先看一下有没有gcc以及gdb

只需输入


gcc -v

gdb -v

img

没有的话就输入以下命令安装


apt-get install gdb

apt-get install gcc

首先在桌面上(任意地方)新建一个文件夹。双击打开vscode,菜单中点击“文件”---》“打开文件夹”打开你刚才创建的文件夹,创建一个cpp文件写一个简单的测试程序

img

“F5”调试,这时会出现缺少配置文件,出现以下选项

img

选择箭头的选项,这时会跳转到launch.json的文件中复制下面的内容覆盖。

launch.json配置文件

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/${fileBasenameNoExtension}.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
}

这时再运行,还是会提示出错缺少task文件,这时会自动再创建一个task.json的文件继续复制下面的内容覆盖

task.json配置文件

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": 
    [
        {
            "label": "build",//任务名,和lanuch.json中的"preLaunchTask":"build"一致
            "type": "shell",
            "command": "g++",
            "args":["-g","${workspaceRoot}/${fileBasenameNoExtension}.cpp","-o","${fileBasenameNoExtension}.out"],//要编译的文件mian_test.cpp,${workspaceRoot}表示vscode所打开的工作目录
            "problemMatcher":
            {
                "owner":"cpp",
                "fileLocation":["relative","${workspaceRoot}"],
                "pattern":
                {
                    "regexp": "^([^\\s].*)\\((\\d+,\\d+)\\):\\s*(.*)$",
                    "file": 1,
                    "line":2,
                    "column":3,
                    "severity": 4,
                    "location": 2,
                    "message": 5
                }
            }
        }
 
    ]
}

完成

img
本片内容配置文件部分内容转自网络

原文地址:https://www.cnblogs.com/cafu-chino/p/11801553.html