Vscode/C + + automatic compilation configuration under Mac

Source: Internet
Author: User

I mac version 10.12.5, Vscode version is 1.13

Step is very simple, add a variety of C + + related Plug-ins, reload once, restart Vscode.

Create a. Vscode folder under the Helloworld.cpp folder and create 2 files in. vscode: Tasks.json, Launch.json

The contents of each file are followed by:

Tasks.json: (compilation configuration, that is, the process of generating a.out with CPP)

{
    //https://go.microsoft.com/fwlink/? linkid=733558
    //For the documentation about the Tasks.json format
    "version": "0.1.0",
    "command": "g++",  //command and args are combined to compile the C + + command, that is g++-G xxx.cpp-o a.out "Isshellcommand"
    : True,
    "args": ["G", "${file}", "-O", "A.out"],  //${file} represents any file name, instead of Helloworld.cpp
    "showoutput": "Always",
    "Problemmatcher": {  // Regular match, delete the useless symbol
        "owner": "CPP",
        "filelocation": ["Relative", "${workspaceroot}"],
        "pattern": {
            " RegExp ":" ^ (. *):(\\d+):(\\d+): \\s+ (Warning|error): \\s+ (. *) $ ",
            " file ": 1,
            " line ": 2,
            " column ": 3,
            "Severity": 4,
            "message": 5
        }
    }
}

Launch.json: (Debug Configuration, which is the process of running a.out)

{
    "version": "0.2.0", "
    Configurations": [
        {
            "name": "(LLDB) Launch",
            "type": "cppdbg",
            " Request ":" Launch ",
            " program ":" ${workspaceroot}/a.out ",//debug, that is, run a.out file
            " args ": [],
            " Stopatentry ": False,
            "CWD": "${workspaceroot}",
            "Environment": [],
            "Externalconsole": True,
            "Mimode": "Lldb",
            "Prelaunchtask": "g++"//representing the g++ instruction in Tasks.json before executing Launch.json}
    ]
}


After configuration, press F5 can be arbitrary in the working directory of CPP file for a key to compile and run debugging


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.