• Debian | Vscode 安装与配置 C 环境


    博客食用更佳哦~ 点我进入博客

    安装 vscode

    sudo apt update
    sudo apt install software-properties-common apt-transport-https curl
    
    curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
    
    sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
    
    sudo apt update
    sudo apt install code
    

    配置环境

    sudo apt install build-essential gdb
    

    安装插件

    下载插件 C/C++

    创建一个 cpp 文件,写入 c++ 代码,并进行 Debug C/C++ File

    #include
    
    using namespace std;
    
    int main()
    {
        cout << "hello" << endl;
        return 0;
    }
    
    选择 g++

    此时在 .vscode 文件夹下会多出 tasks.json

    {
        "tasks": [
            {
                "type": "cppbuild",
                "label": "C/C++: g++ build active file",
                "command": "/usr/bin/g++",
                "args": [
                    "-fdiagnostics-color=always",
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}"
                ],
                "options": {
                    "cwd": "${fileDirname}"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "Task generated by Debugger."
            }
        ],
        "version": "2.0.0"
    }
    

    同时,终端输出 hello

    按 Ctrl + Shift + P 在上方输入 configuration
    找到 C/C++: Edit Configurations(JSON) 并点击

    此时在 .vscode 目录下面会多出 c_cpp_properties.json

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/**"
                ],
                "defines": [],
                "compilerPath": "/usr/bin/gcc",
                "cStandard": "c17",
                "cppStandard": "gnu++17",
                "intelliSenseMode": "linux-gcc-x64"
            }
        ],
        "version": 4
    }
    

    点击左侧 Run and Debug 图标:
    点击 create a launch.json file

    选择 C++ (GDB/LLDB)

    {
        // 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": "g++ - Build and debug active file",
                "type": "cppdbg",
                "request": "launch",
                "program": "${fileDirname}/${fileBasenameNoExtension}",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${fileDirname}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
                "preLaunchTask": "C/C++: g++ build active file",
                "miDebuggerPath": "/usr/bin/gdb",
            }
        ]
    }
    

    解决终端出现 [1] + Done “/usr/bin/gdb” --interpreter=mi --tty=${DbgTerm} 0<“/tmp/Microsoft-MIEngine-In-wyyxzchw.1pu” 1>“/tmp/Microsoft-MIEngine-Out-qddpshqk.bcg”

    在 launch.json 的 configuration 中添加:

    "miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /usr/bin/gdb -q --interpreter=mi",
    

    重新编译运行

    最终,launch.json 内容为

    {
        // 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": "g++ - Build and debug active file",
                "type": "cppdbg",
                "request": "launch",
                "program": "${fileDirname}/${fileBasenameNoExtension}",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${fileDirname}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
                "preLaunchTask": "C/C++: g++ build active file",
                "miDebuggerPath": "/usr/bin/gdb",
                "miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /usr/bin/gdb -q --interpreter=mi",
            }
        ]
    }
    
  • 相关阅读:
    [附源码]java毕业设计共享图像网站
    【刷题日记】8.二分查找
    暑期JAVA学习(37)定时器
    北斗卫星:助力森林病虫害防治监测的革新技术
    kafka—消费者
    java技术专家面试指南80问【java学习+面试宝典】(二)
    openGauss学习笔记-89 openGauss 数据库管理-内存优化表MOT管理-内存表特性-使用MOT-MOT使用查询原生编译
    二叉堆------小根堆
    java项目-第144期ssm农产品供销服务系统-java毕业设计_计算机毕业设计
    当new一个对象时在JVM中会有哪些操作
  • 原文地址:https://blog.csdn.net/DaphneOdera17/article/details/140963658