繁体   English   中英

在Visual Studio Code中编译C ++代码

[英]Compiling C++ code in Visual Studio Code

我安装了Microsoft推荐的C / C ++扩展。 我现在希望修复编译。

我知道Visual Studio代码是没有内置编译器的编辑器,但是关于如何实现修复配置以编译代码的任务的信息很少甚至没有。

我运行linux ubuntu 14.04并安装了gcc编译器。 我希望使用它来编译代码。

我一直在看任务,在启动时处于调试模式时,它会进入此文件:

lanuch.json(这些是启动配置):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "launchOptionType": "Local",
            "targetArchitecture": "x64",
            "program": "enter program name, for example ${workspaceRoot}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true
        },
        {
            "name": "C++ Attach (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "launchOptionType": "Local",
            "targetArchitecture": "x64",
            "program": "enter program name, for example ${workspaceRoot}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "processId": "enter program's process ID",
            "externalConsole": false
        }
    ]
}

从这里我迷路了。 我实际上不知道在这里要更改什么。

同样从此https://code.visualstudio.com/docs/editor/tasks中,有一个任务示例:

{
    "version": "0.1.0",
    "command": "gcc",
    "args": ["-Wall", "helloWorld.c", "-o", "helloWorld"],
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

同样,我不知道如何编辑它,以便它可以编译我的代码。

我有包含我的主要功能的文件start.cpp。

那么,如何设置Visual Studio代码以最简单,最自动化的方式来编译代码?

安装用于Visual Studio代码的“代码运行器扩展”,您的代码应该可以正常工作。

编辑task.json文件并将其粘贴;

{
    "version": "2.0.0",
    "tasks": [
    {
        "label": "Build",
        "type": "shell",
        "command": "g++ ${file} -o ${fileDirname}/${fileBasenameNoExtension}.out & ${fileDirname}/${fileBasenameNoExtension}.out",
        "args": [

        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM