gpt4 book ai didi

c++ - 如何配置 VS Code 来编译/调试 C++?

转载 作者:行者123 更新时间:2023-11-28 02:04:10 24 4
gpt4 key购买 nike

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

另外,这个扩展是指 Clang 工具,我假设 Clang 不能在 Windows 上运行。

最佳答案

这是一个网页,他们在其中解释了有关 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 并为构建任务添加以下键绑定(bind):

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

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

关于c++ - 如何配置 VS Code 来编译/调试 C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38235451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com