ubuntu下用visual studio code调试C++

尽管VS Code本质上是一个编辑器,但是对插件的友好支持使得它可以成为很好用的IDE(用完以后果断抛弃了CLion、QTcreator、Kdevelop等一系列IDE),从此只用一个VS CODE。
用VS CODE可以很方便地对C++程序进行debug,以linux Ubuntu环境为例:
Ctrl+Shift+D调出debug界面,然后点左上角的设置按钮,选择C/C++,出现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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "enter program name, for example ${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

只用对programargs两项设置即可,如设置成:

            "program": "${workspaceFolder}/build/drivable",
            "args": ["build/file.pcd"],

相当于在终端下:

${workspaceFolder}
./build/drivable build/file.pcd

设置好后按F5即可调试,加断点等和其他IDE一样

reference:C/C++ for Visual Studio Code

你可能感兴趣的:(计算机视觉)