在Deepin 20 beta配置安装Visual Studio Code Insider的C++教程

2 篇文章 0 订阅
1 篇文章 0 订阅

先下载Visual Studio Code Insider的deb包:https://code.visualstudio.com/insiders/
接下来在终端输入这句话并回车运行:

sudo apt install gcc g++ gdb

然后在系统的随便某个地方(比如主目录)建一个文件夹(我皮建了两个,是“/home/q4927/Devtools/C++”)
接下来打开Visual Studio Code Insider,安装这些扩展

名称: Chinese (Simplified) Language Pack for Visual Studio Code
id: ms-ceintl.vscode-language-pack-zh-hans
说明: Language pack extension for Chinese (Simplified)
版本: 1.37.5
发布者: Microsoft
VS Marketplace 链接: https://marketplace.visualstudio.com/items?itemName=MS-CEINTL.vscode-language-pack-zh-hans

名称: C/C++
id: ms-vscode.cpptools
说明: C/C++ IntelliSense, debugging, and code browsing.
版本: 0.24.1
发布者: Microsoft
VS Marketplace 链接: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

下面是可选:

名称: Live Share
id: ms-vsliveshare.vsliveshare
说明: Real-time collaborative development from the comfort of your favorite tools.
版本: 1.0.614
发布者: Microsoft
VS Marketplace 链接: https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare

名称: Visual Studio IntelliCode
id: visualstudioexptteam.vscodeintellicode
说明: AI-assisted development
版本: 1.1.8
发布者: Microsoft
VS Marketplace 链接: https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode

安装完毕后,重启Visual Studio Code Insider,点击打开文件夹
选择你建的文件夹(比如我的“/home/q4927/Devtools/C++”)

建一个C++文件(我的是qwq.cpp)
然后随便打可以运行的代码,比如我的:

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"qwq"<<endl;
    return 0;
}

接下来先按Ctrl+Shift+P,输入以及选择“Edit Configurations (UI)”
在打开的页面中,“Compiler path”改成“/usr/bin/g++”
接下来点击调试、运行(g++),系统会生成launch.json,我的内容如下:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

接下来按Ctrl+Shift+P,输入以及选择“Tasks:Configure Task”
系统会生成“tasks.json”,我的是这样的:

{
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: cpp build active file",
            "command": "/usr/bin/cpp",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "shell",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

其实还有一个文件,是“c_cpp_properties.json”,我的是:

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

好了,这下应该可以调试和运行了。
运行结果在自带的下面的方框里面。

谢绝转载

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值