从 GNU makefile 调用 Windows 命令(例如 del)
使用GNU Make 似乎无法调用Windows 系统命令(例如del、move 等)。我正在尝试创建一个不依赖于用户安装额外工具(例如来自 Cygwin 的 rm.exe
)的 makefile。
运行下面的规则时,报错del: command not find
:
clean:
del *.o
这大概是因为没有“del”这样的可执行文件。我也尝试过将其作为 cmd
的选项运行,但这似乎只会打开一个新提示:
clean:
cmd /C del *.o
我正在使用 Windows XP (5.1.2600) 和捆绑的 GNU Make 3.79.1作为 MSys 的一部分。
It does not appear to be possible to call Windows system commands (e.g. del, move, etc) using GNU Make. I'm trying to create a makefile that doesn't rely on the user having extra tools (e.g. rm.exe
from Cygwin) installed.
When the following rule is run, an error is reported del: command not found
:
clean:
del *.o
This is presumably because there is no such execuatable as "del". I've also tried running it as an option to cmd
but with this only seems to open a new prompt:
clean:
cmd /C del *.o
I'm using Windows XP (5.1.2600) with GNU Make 3.79.1 that is bundled as part of MSys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
似乎
/C
开关需要转义,因为/
在 GNU Make 中被解释为路径。以下内容按预期工作:It seems the
/C
switch needs to be escaped because a/
is interpreted as a path in GNU Make. The following works as expected:因为基于 DOS 的系统有两个不同的命令用于删除文件和目录,所以我发现有两个不同的定义效果最好:
Because DOS-based systems have two different commands for removing files and directories, I find that having two different defines works the best:
我也发生过。在 makefile 的顶部添加:
由于您是在 Windows 上编译,因此选择“cmd”作为默认 shell。这
这很重要,因为 GNU make 将搜索类似 linux/unix shell 的路径,如果找到,它将使用它。安装cygwin时就是这样。此行为的副作用是找不到“del”和“echo”等命令。如果我们告诉 GNU make 使用“cmd”作为其 shell,那么“del”等将可用。
Happened to me too. At the top of your makefile add:
Since you are compiling on windows, select 'cmd' as the default shell. This
is important because GNU make will search the path for a linux/unix like shell and if it finds one it will use it instead. This is the case when cygwin is installed. The side effect of this behavior is that commands like 'del' and 'echo' are not found. If we tell GNU make to use 'cmd' as its shell, then 'del' and such will be available.
del
是cmd.exe
(以及之前的command.com
)的内置命令。你的命令 cmd /C del *.o 应该可以工作,如果它启动一个新的命令提示符,我怀疑 cmd 可能是一个包装器。您是否尝试过使用其完整路径(例如c:/WINDOWS/system32/cmd.exe)来调用cmd?del
is a builtin command ofcmd.exe
(as well as previouslycommand.com
). Your commandcmd /C del *.o
should work, if it starts a new command prompt I suspect that cmd maybe might be a wrapper. Have you tried to call cmd with its full path (e.g. c:/WINDOWS/system32/cmd.exe)?Tom Longridge 的答案对我来说接近事实,但转义需要在 Windows Vista Business 计算机上的正斜杠之前使用反斜杠来完成,我需要这样做:
Tom Longridge's answer was close to the truth for me, but the escaping needed to be done using a backslash before the forward slash on the Windows Vista Business machine I was needing this for:
另一个解决方案是创建一个
del.bat
文件,其中包含:然后
makefile
可以简单地包含此内容以清理 makefile,但可能会使您的构建目录稍微混乱。
Another solution is to create a
del.bat
file containing:then the
makefile
can simply containthis cleans up the makefile, but may clutter your build directory slightly.
我刚刚完成这个。我不确定 DOS/Windows 中的情况是否发生了变化,但这就是当前版本必须格式化的方式。
I just completed this. I am not sure if things have changed in DOS/Windows but this was how it had to be formatted with current versions.