Ubuntu16.04安装并配置Visual Studio调试C++

Ubuntu16.04安装并配置Visual Studio调试C++

1. 安装Visual Studio

c 复制代码
sudo snap install --classic code

2.VSCode 插件安装

我们需要按照的插件有下面几个:

1)、C/C++,这个肯定是必须的。

2)、C/C++ Snippets,即 C/C++重用代码块。

3)、C/C++ Advanced Lint,即 C/C++静态检测 。

4)、Code Runner,即代码运行。

5)、Include AutoComplete,即自动头文件包含。

6)、Rainbow Brackets,彩虹花括号,有助于阅读代码。

7)、One Dark Pro,VSCode 的主题。

8)、GBKtoUTF8,将 GBK 转换为 UTF8。

9)、ARM,即支持 ARM 汇编语法高亮显示。

10)、Chinese(Simplified),即中文环境。

11)、vscode-icons,VSCode 图标插件,主要是资源管理器下各个文件夹的图标。

12)、compareit,比较插件,可以用于比较两个文件的差异。

13)、DeviceTree,设备树语法插件。

3.VS Code文件配置

1.对Visual Studio Code软件中的部分.json文件进行配置。

首先,在Visual Studio Code软件左侧菜单栏中,选择"Run and Debug"选项,并点击下图所示红色圈内的蓝色字体。

将显示出launch.json文件修改为:

c 复制代码
{
    // 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
                }
            ]
        }
        ]
}

2.接下来,同时按下Ctrl键、Shift键与P键,唤起搜索框,并输入Tasks: Run Task,并选择这一项,点击右侧出现的齿轮标志。
将显示出tasks.json文件修改为:

c 复制代码
{
    "tasks": [
        {
            "type": "shell",
            "label": "build",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-std=c++11",
                "-o",
                "${fileBasenameNoExtension}.out"
            ]
        }
    ],
    "version": "2.0.0"
}

4.调试c++

Ctrl+S:保存代码;

F5:debug;

Ctral+F5:直接运行

参考

  1. Ubuntu16.04LTS安装Visual Studio Code
  2. Ubuntu下Visual Studio Code软件的安装和使用
  3. VS Code文件配置
相关推荐
晚风残1 小时前
【C++ Primer】第六章:函数
开发语言·c++·算法·c++ primer
满天星83035771 小时前
【C++】AVL树的模拟实现
开发语言·c++·算法·stl
Mr_WangAndy2 小时前
C++设计模式_行为型模式_责任链模式Chain of Responsibility
c++·设计模式·责任链模式·行为型模式
时间之里2 小时前
【c++】:Lambda 表达式介绍和使用
开发语言·c++
汉克老师3 小时前
GESP2025年9月认证C++四级( 第三部分编程题(1)排兵布阵)
c++·算法·gesp4级·gesp四级
·心猿意码·4 小时前
C++智能指针解析
开发语言·c++
property-5 小时前
C++中#define和const的区别
开发语言·c++
怎么没有名字注册了啊6 小时前
查找成绩(数组实现)
c++·算法
AI+程序员在路上7 小时前
QT6中Combo Box与Combo BoxFont 功能及用法
c++·qt
L_09077 小时前
【Algorithm】Day-4
c++·算法·leetcode