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

2023-11-30

微软的视觉工作室代码编辑器相当不错,但它没有默认支持构建 C++ 项目。

我如何配置它来执行此操作?


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

Following the instructions here, press Ctrl + Shift + P, type Configure Tasks, select it and press 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",

            // 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
                }
            }
        }
    ]
}

现在转到菜单File优先键盘快捷键,并为构建任务添加以下键绑定:

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

Now when you press F8 the Makefile will be executed, and errors will be underlined in the editor.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何设置 Visual Studio Code 来编译 C++ 代码? 的相关文章

随机推荐