【问题标题】:Building a C++ Program in Visual Studio Code在 Visual Studio Code 中构建 C++ 程序
【发布时间】:2017-08-12 18:59:35
【问题描述】:

据我所知,我已按照所有步骤在 Windows 10 上的 Visual Studio Code 中构建 C++ 程序。我在 C:/MinGW 下安装了 gcc-7.1.0-64,在 VS Code 中安装了 C/C++ 扩展,并且为我的HelloWorld.cpp 配置了构建任务。

问题:

当我尝试通过打开命令面板然后输入Tasks: Run Build Task 来构建程序时,它会显示错误:

未找到构建任务。按“配置构建任务”来定义一个。

尽管我已经做到了这一点。我可能遗漏了一些简单的东西,但是我在任何地方都找不到任何教程或文档来解释如何完成这项工作。任何帮助表示赞赏。

HelloWorld.cpp

#include <iostream>

using namespace std;

int main() {
  std::cout << "Hello world\n";
}

c_cpp_properties.json(从 sn-p 中省略不相关的 Mac/Linux 设置)

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "C:/MinGW/include/c++/7.1.0/*"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "browse": {
                "path": [
                    "${workspaceRoot}",
                    "C:/MinGW/include/c++/7.1.0/*"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 2
}

tasks.json

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "taskName": "HelloWorld.cpp",
      "command": "c++",
      "args": ["-g", "HelloWorld.cpp"],
      "type": "shell"
    }
  ]
}

【问题讨论】:

    标签: c++ visual-studio-code


    【解决方案1】:

    感谢@RobLourens 对答案的评论。

    tasks 2.0 最简单的方法是运行“配置默认构建任务”,这将让您选择构建命令,并为您设置组属性。

    我很快意识到它在tasks.json中指定构建任务的"group"部分下面添加了一行:(可以手动添加以规避形式化方法

    "isDefault": true,
    

    【讨论】:

      【解决方案2】:

      只需在您的任务中添加"isBuildCommand": true

      【讨论】:

      • IntelliSense 抱怨:The property isBuildCommand is deprecated. Use the group property instead. See also the 1.14 release notes.
      • 这是旧任务格式的属性。任务 2.0 最简单的方法是运行“配置默认构建任务”,这将让您选择构建命令,并为您设置组属性。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多