【问题标题】:Compiling C++ code in Visual Studio Code在 Visual Studio Code 中编译 C++ 代码
【发布时间】:2016-10-20 22:51:38
【问题描述】:

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

我知道 Visual Studio Code 是一个没有内置编译器的编辑器,但是几乎没有关于如何完成修复配置以编译代码的任务的信息。

我运行 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 代码以最简单、最自动化的方式编译代码?

【问题讨论】:

标签: c++ linux visual-studio compilation visual-studio-code


【解决方案1】:

编辑 tasks.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
        }
    }]
}

【讨论】:

    【解决方案2】:

    为 Visual Studio 代码安装“Code Runner Extension”,您的代码应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-24
      • 1970-01-01
      • 2019-06-28
      • 2021-06-11
      • 2020-12-01
      • 1970-01-01
      • 2019-05-28
      • 1970-01-01
      相关资源
      最近更新 更多