Linux under the VS Code C ++ project configuration

ready

Installation VSCode , can directly download the deb package to install, after installation is complete C / C ++ for Visual Studio Code plug-ins, after the installation reboot (no need to restart after the latest 1.3 version).

Build directory and files

[Test] New Folder, and create a new file helloworld.cpp document, which reads as follows,

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
    cout<< "hello world" << endl;
    return 0;
}

Open the folder using vscode

Configuration c ++ IntelliSense

Use F1, open a command option, enter the C / C ++, select C / C ++: Edit configuration, generate c_cpp_properties.json profile.

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Chief among these is a reference path and "includePath" library, configured according to the citation.

launch

In the debug screen, select Add Configuration, and then select only c ++ (gdb / lgdb) option to generate launch.json name suggests this document primarily serving the debugging load control

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/helloworld",
            "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
                }
            ]
        }
    ]
}

Note that the parameters for the "program", this is the target file needs to be debugged, should be set to the file location compiled output; followed by the need to add "preLaunchTask", this name should be built with the following tasks in the name of tasks.json consistent.

tasks.json

Enter the task in the command window, select the task: configure task option generates tasks.json file

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args":[
                "-g","helloworld.cpp","-o","helloworld"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Note launch.json in "preLaunchTask" calls and "label" the same task.

Start Debugging

Press F5 to start debugging it, everything is so simple, a good start of the journey.

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159633.htm