繁体   English   中英

如何在 Visual Studio 代码中制作目标“makefile”?

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

我试图弄清楚如何在 vs 代码环境中编译我的 c++ 代码。

我可以使用 g++ 进行编译,但我还无法在 vs 代码中弄清楚。

我使用了这个问题中 BeeOnRope 的答案来设置我的构建命令和相关的热键。

如何设置 Visual Studio Code 来编译 C++ 代码?

出来的错误是这个

make: *** 没有生成目标`Makefile'的规则。 停止。 终端进程以退出代码终止:2


编辑:在我的 tasks.json 上工作后,它看起来像这样,但是我仍然遇到上面显示的相同错误。

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

在您的 tasks.json 中,添加/编辑“command”和“args”字段以拥有您将手动运行的构建命令行。 那可以是 g++、make 或其他任何东西。 看这里:

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


更新:查看您发布的 tasks.json 文件,您的命令需要进入任务。 像这样的东西:

{
    // 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,在此处格式化代码的一种方法是全部缩进:

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

另一种方法是用三个反引号包裹它(不需要缩进,虽然我在这里这样做是为了我可以在反引号内加上反引号):

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM