c++ - 如何在 visual studio 代码中创建目标 'makefile'?

标签 c++ visual-studio-code

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

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

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

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

出来的错误是这样的

make: *** No rule to make target `Makefile'. Stop. The terminal process terminated with exit code: 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!" );
    }
    ```

关于c++ - 如何在 visual studio 代码中创建目标 'makefile'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54678838/

相关文章:

C++ 为什么 empty set::emplace() 将一个元素插入到一组指针中?

c++ - 如何在 C++ 中将字节数组发送到另一个进程

python - VS Code Code Runner 不适用于 virtualenvs

python - Anaconda/Python/VSCode : vscode editor doesn't recognize installed packages

c# - 使用 C# 测试 C++ 代码时的代码覆盖率

c++ - openCV 创建不同大小的 3D 矩阵

c++ - 无法从 'int' 转换为 'int *'

c++ - 名称带有空格的文件不会被编译

c# - 我应该使用什么 gulp 插件在 Mac 上构建 ASP.NET 5?

php - Visual Studio Code : Unable to locate phpcs