文章目录

  • 一. 可视化的代码跟踪调试
  • 1.基于跨平台多类型代码编辑器VScode
  • 1下载vscode
  • 2.在vscode配置C/C++
  • 3.编译运行
  • 二、总结
  • 三、参考资料


一. 可视化的代码跟踪调试

1.基于跨平台多类型代码编辑器VScode

1下载vscode

第一种(不太推荐,安装速度超级慢)

1.找到应用商店

ubuntu vscode配置python环境_json


2.搜索Visual Studio Code,找到下载即可

ubuntu vscode配置python环境_json_02


第二种

1找到vscode的官网

ubuntu vscode配置python环境_g++_03


2.将压缩包放在主目录下

ubuntu vscode配置python环境_g++_04


3.安装

sudo dpkg -i code_1.51.0-1604600753_amd64.deb

ubuntu vscode配置python环境_json_05


能在全部应用中找到即可

ubuntu vscode配置python环境_ubuntu_06

2.在vscode配置C/C++

1.在vscodee里安装C++的插件

ubuntu vscode配置python环境_ubuntu_07


2.配置调试和编译文件,launch.json和task.json

首先新建一个vscode的目录,再在vscode的目录下新建一个main.cpp的文件,因为vscode要调试时,只能打开含有源代码的文件,而非空文件

打开vscode的文件

ubuntu vscode配置python环境_json_08


在vscode文件下创建main.cpp

ubuntu vscode配置python环境_g++_09


简单代码

#include <iostream>
using namespace std;
int main()
{
    cout << "HELLO WORLD" << endl;
    return 0;
}

打开文件,并选择第四个三角形的符号的图标点击

ubuntu vscode配置python环境_json_10


点击Run and Debug

ubuntu vscode配置python环境_ubuntu_11


得到launch.json,修改

ubuntu vscode配置python环境_g++_12

修改launch.json,将progarm的内容修改以及externalConsole的false改成true

{
    // 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
                }
            ]
        }
    ]
}

再得到tasks.json

ubuntu vscode配置python环境_g++_13


ubuntu vscode配置python环境_json_14


ubuntu vscode配置python环境_ubuntu_15

修改tasks.json,将label的内容改为build,command的内容改为g++,并添加args

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0", //该tasks.json文件采用的版本号,目前默认为2.0.0版本
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-std=c++11",
                "-o",
                "${fileBasenameNoExtension}.out"
            ],
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

至此配置完毕

3.编译运行

按shift+cirl+B编译,编译成功出现

ubuntu vscode配置python环境_json_16


摁(gdb)Launch,调试即可出现终端

ubuntu vscode配置python环境_json_17


调试成功

ubuntu vscode配置python环境_ubuntu_18

二、总结

学习了在ubuntu下使用vscode来调试代码。

三、参考资料

在ubuntu18.04版本安装vscodeUbuntu16.04配置Visual Studio Code C++开发环境在ubuntu中用vscode编译调试C\C++Ubuntu下使用可视化调试前端软件KDBG和VScode