在Visual Studio代码中构建一个C++程序代码

问题描述:

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

问题:

当我尝试打开命令面板,然后键入Tasks: Run Build Task筹建方案,它显示错误:

No Build Task found. Press 'Configure Build Task' to define one.

尽管我有已经完成了。我可能错过了一些简单的东西,但没有任何教程或文档可以在任何地方找到解释如何使这项工作。任何帮助表示赞赏。

HelloWorld.cpp

#include <iostream> 

using namespace std; 

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

c_cpp_properties.json(无关的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" 
    } 
    ] 
} 

感谢@ RobLourens对答案的评论。

The easiest way for tasks 2.0 is, run "Configure default build task", which will let you pick the build command, and set the group property for you.

我很快意识到,它增加了下指定的生成任务的"group"截面的线在tasks.json:(可以手动添加到规避正式方法

"isDefault": true, 

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

+0

智能感知抱怨说:该属性isBuildCommand已弃用。改用组属性。另见1.14发行说明.' – ifconfig

+1

这是来自旧任务格式的属性。任务2.0最简单的方法是运行“配置默认构建任务”,这将允许您选择构建命令,并为您设置组属性。 –