ubuntu build debugging environment based VSCode the C ++ programming language to build guide

ubuntu build debugging environment based VSCode the C ++ programming language to build guide

First install g ++

sudo apt install g++
  • Check whether the installation was successful:

Plug in the plug-in bar c / c ++, code runner:

First, write a simple demo.cpp file:

'''

#include<iostream>
using namespace  std;
int main()
{
    int i = 0 ;
    int  num =0;
    for ( ; i < 10; i++)
    {
        num +=  i;
    }
    cout<<"结果是"<<num<<endl;
    return 0;
}

'''

Generate a configuration file tasks.json:

  1. Terminal -> Default configuration generation task
  2. input ctrl + shift + p c / c ++ appears in the command line

'''

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

'''

Generate launch.json configuration file:

ctrl + shift + p command line: Debug

'''

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: 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",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

'''

Run demo.cpp: Right-click on the upper right or select Run to run the triangle symbol

Debugging:

Guess you like

Origin www.cnblogs.com/lhx9527/p/12596281.html