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文件配置
相关推荐
Je1lyfish7 小时前
CMU15-445 (2025 Fall/2026 Spring) Project#3 - QueryExecution
linux·c语言·开发语言·数据结构·数据库·c++·算法
Brilliantwxx7 小时前
【C++】 vector(代码实现+坑点讲解)
开发语言·c++·笔记·算法
叼烟扛炮8 小时前
C++第三讲:类和对象(中)
开发语言·c++·类和对象
KuaCpp8 小时前
C++新特性学习
c++·学习
墨染千千秋9 小时前
C/C++ Keywords
c语言·c++
ximu_polaris9 小时前
设计模式(C++)-行为型模式-中介者模式
c++·设计模式·中介者模式
CSCN新手听安10 小时前
【Qt】Qt窗口(八)QFontDialog字体对话框,QInputDialog输入对话框的使用,小结
开发语言·c++·qt
tumu_C11 小时前
用std::function减缓C++模板代码膨胀和编译压力的一个场景
开发语言·c++
Hical6111 小时前
C++17 实战心得:那些真正改变我写代码方式的特性
c++
Hical6112 小时前
实测:C++20 协程 vs Go Gin vs Rust Actix,谁的 Web 性能更强?
c++