【问题标题】:How to configure VS Code to compile/debug C++?如何配置 VS Code 来编译/调试 C++?
【发布时间】:2016-07-06 23:32:00
【问题描述】:

我已经为 VS Code 安装了 C/C++ 扩展,但我不太确定我的tasks.json 中需要什么才能编译项目。有没有什么地方可以看的例子?

此外,扩展名指的是 Clang 工具,我有点假设 Clang 在 Windows 上不起作用。

【问题讨论】:

  • 您可以创建一个 build.bat,使用您想要的参数调用 cl,然后通过下面的方案创建一个调用它的任务,或者您可以创建一个直接调用 cl 的任务。

标签: c++ visual-c++ visual-studio-code


【解决方案1】:

这是一个网页,他们在其中解释了有关 task.json 文件的更多信息。

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

构建任务是项目特定的。要创建一个新项目,请在 VSCode 中打开一个目录。

按照说明here,按Ctrl+Shift+P,输入Configure Tasks,选择它并按Enter

tasks.json 文件将被打开。将以下构建脚本粘贴到文件中,并保存:

{
    "version": "0.1.0",
    "command": "make",
    "isShellCommand": true,
    "tasks": [
        {
            "taskName": "Makefile",
            // Make this the default build command.
            "isBuildCommand": true,
            // Show the output window only if unrecognized errors occur.
            "showOutput": "always",
            // No args
            "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
                }
            }
        }
    ]
}

现在转到File->Preferences->Keyboard Shortcuts 并为构建任务添加以下键绑定:

// Place your key bindings in this file to overwrite the defaults
[
    { "key": "f8",          "command": "workbench.action.tasks.build" }
]

现在,当您按下F8 时,Makefile 将被执行,错误将在编辑器中加下划线。

【讨论】:

  • 我在 Windows 上,'make' 未被识别为内部或外部命令、可运行程序或批处理文件。
  • 我不明白你在做什么
  • 我正在尝试在 Windows 上编译和运行 C++ 应用程序。使用 MSVC。
猜你喜欢
  • 2020-09-11
  • 2018-06-14
  • 2020-08-25
  • 2019-10-23
  • 2019-10-20
  • 2018-08-16
  • 2017-02-13
  • 2022-06-13
  • 2022-06-15
相关资源
最近更新 更多