c - 使用 Visual Studio Code 任务自动化多个文件夹中的 C makefile
问题描述
我有一个用 C 语言编写的项目,它有两个 make 文件,一个在主目录中,一个在子目录中。我想使用 VS Code 任务来自动化制作过程,这样我就不必每次想运行时都使用终端来制作项目。相反,我只想使用ctrl+shift+b
然后从终端运行我的代码mpiexec
。
我在项目主文件夹内的 .vscode 目录中创建了 tasks.json 文件。tasks.json 当前包含我基于本教程的以下代码。
{
"version": "2.0.0",
"command": "bash",
"tasks": [
{
"label": "Make Project",
"type": "shell",
"command": "cd ${workspaceFolder}",
"args": ["make"],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": "$msCompile"
}
]
}
我希望这与make
在当前工作目录的位置输入终端的行为相同。相反,这是终端的输出
Executing task: 'cd /home/git/project' make <
/bin/bash: cd /home/git/project: no such file or directory
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
请注意,make 文件位于 /home/git/project。我希望然后在 /home/git/project/subfolder 中构建一个 make 文件。
为什么初始命令不工作cd /home/git/project
,然后make
工作?我需要用跑步者把它分成几个不同的任务吗?我是使用 VS Code 的新手,因此不胜感激。谢谢。
解决方案
我实现的解决方案如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "msvc build",
"type": "shell",
"command": "",
"args": [
"make",
"--directory=${workspaceFolder};",
"make",
"--directory=${workspaceFolder}/subfolder"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal":"always"
},
"problemMatcher": "$msCompile"
}
]
}
基于Reinier Torenbeek 的建议以及Microsoft 页面上的这篇文章。这里要注意的要点是,我没有向 shell 传递任何命令,而只是传递了 args。
ctrl+shift+b
我现在可以通过在编辑器中按下来构建我项目中的所有 makefile,因为group
设置为build
.
推荐阅读
- javascript - 单击侧边栏项目时如何更改主要内容
- javascript - 减慢循环或创建动画?
- django - 将 db 值打印到 html django
- f# - 解析函数参数中没有参数的函数调用 - FParsec
- typescript - 如何省略对象传播中的字段?
- ios - 如何使用框架使 UILabel 居中:CGRect
- haskell - 修补不带 < 的递归定义列表
> - sql - BINARY_CHECKSUM - 不同的结果取决于行数
- html - 在省电模式下,无法在移动设备 (iOS) 上点击视频中的链接
- google-cloud-platform - 存储 JSON API 何时可以返回 HTTP 重定向?