嵌入式学习小组
直播中

juju宇哥

8年用户 1367经验值
擅长:479809
私信 关注

Linux使用VScode编译调试C/C++程序的过程是怎样的

如何安装VScode?

Linux使用VScode编译调试C/C++程序的过程是怎样的

回帖(1)

李云逍

2021-12-24 17:00:59
一、安装VScode

在ubuntu中找到Ubuntu Software

点击右上角弹出搜索框并搜索vscode,进去后点击install下载

二、环境构建

打开VScode,在搜索栏中搜索C/C++,并点击install进行插件的下载

选择打开一个文件夹,并在文件夹中新建一个文件hello.cpp

输入代码:

#include
using namespace std;
int main()
{
    cout<<"hello world!"<     return 0;
}
搭建环境


完成后会得到默认生成的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": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",q
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}
生成tasks.json文件


然后将其中的代码替换成以下代码:

{
        "version": "2.0.0",
        "tasks": [
                {
                        "label": "build",
                        "type": "shell",
                        "command": "g++",
                        "args": [
                                "-g",
                                "${file}",
                                "-std=c++11",
                                "-o",
                                "${fileBasenameNoExtension}.out"
                        ]
                }
        ]
}
然后即可在.cpp文件中开始调试

三 、参考

Ubuntu下使用可视化调试前端软件KDBG和VScode
Ubuntu中用VScode编译调试CC++
举报

更多回帖

发帖
×
20
完善资料,
赚取积分