ifconfig
ifconfig

Reputation: 6832

Building a C++ Program in Visual Studio Code

To my knowledge, I have followed all of the steps to build a C++ program in Visual Studio Code on Windows 10. I have gcc-7.1.0-64 installed under C:/MinGW, the C/C++ extension installed in VS Code, and have configured a build task for my HelloWorld.cpp.

The issue:

When I try to build the program by opening the Command Palette and then typing Tasks: Run Build Task, It displays the error:

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

despite the fact that I have already done exactly that. I am probably missing something simple, but no tutorial or documentation I could find anywhere explains how to make this work. Any help is appreciated.

HelloWorld.cpp

#include <iostream>

using namespace std;

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

c_cpp_properties.json (irrelevant Mac/Linux setup omitted from snippet)

{
    "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"
    }
  ]
}

Upvotes: 1

Views: 2605

Answers (2)

ifconfig
ifconfig

Reputation: 6832

Thanks to @RobLourens's comment for the answer.

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.

I soon realized that it adds a line under the "group" section of the specified build task in tasks.json: (may be added manually to circumvent the formal method)

"isDefault": true,

Upvotes: 2

gmardau
gmardau

Reputation: 409

Just add "isBuildCommand": true inside your task.

Upvotes: 1

Related Questions