financial_physician
financial_physician

Reputation: 1998

How can I make a target 'makefile' in visual studio code?

I'm trying to figure out how to compile my c++ code within the vs code environment.

I'm able to compile using g++ but I haven't been able to figure it out in vs code yet.

I used the answer from BeeOnRope from this question to set up my build command and the associated hotkey.

How do I set up Visual Studio Code to compile C++ code?

The error that comes out is this

make: *** No rule to make target `Makefile'. Stop. The terminal process terminated with exit code: 2


Edit: After working on my tasks.json it looks like this, however I'm still getting the same error shown above.

{
    "version": "2.0.0",
    "command": "make",
    "tasks":[
        {
            "label": "Makefile",

            "group": "build",

            // Show the output window only if unrecognized errors occur.
            "presentation": {"reveal": "always"},

            // Pass 'all' as the build target
            "args": ["all"],

            // Use the standard less compilation problem matcher.
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

Upvotes: 4

Views: 9630

Answers (1)

metal
metal

Reputation: 6332

In your tasks.json, add/edit the "command" and "args" fields to have the build command line you would run manually. That could be g++, make, or whatever. See here:

https://code.visualstudio.com/docs/editor/tasks


Update: Looking at the tasks.json file that you posted, your command needs to go inside a task. Something like this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "My Build",
            "group": "build",
            "type": "shell",
            "command": "g++",
            "args": [
               "-o", "LexParse", "Lexxy.cpp", "Parzival.cpp"
            ]
        }
    ]
}

PS, One way to format your code here is to indent it all:

    int main 
    {
        []( auto world ) { return "Hello"s + world; } ( ", World!" );
    }

Another way is to wrap it in three backticks (no need to indent, though I do here so I can have backticks within backticks):

    ```
    int main 
    {
        []( auto world ) { return "Hello"s + world; } ( ", World!" );
    }
    ```

Upvotes: 2

Related Questions