为什么 make.exe 会在 Windows 上尝试 运行 /usr/bin/sh?

Why does make.exe try to run /usr/bin/sh on Windows?

我最近从 Window 7 移动到 Windows 10,我无法让我的 makefile 工作了。

我一直在使用GNU Make for Windows

我注意到的第一件事是它开始将 Windows 文件夹分隔符(反斜杠字符“\”)视为行继续字符,因此我修改了 'clean' 部分,如下所示使用正斜杠“/”字符代替:

clean:
    del $(ObjDir)/*.o

当我调用 make -ftest.mak clean 时出现以下错误,这表明它现在正在 MinGw/Cygwin 环境中尝试 运行:

c:\Test\Source>make -ftest.mak clean
del obj/*.o
/usr/bin/sh: del: command not found
make: *** [clean] Error 127

我的 PC 上确实有 MinGw 文件夹(我已将其重命名以停止查找它)并且在我的 Cmd.exe 环境或 PATH 中看不到任何 'MingGw' 相关的环境变量

如何让 make 正常工作,使其不会尝试在 Windows 下执行 sh

是否有某个配置参数使其调用 sh 而不是 cmd.exe

更新:刚刚尝试 运行ning make -d 记录调试输出。看起来好像它正在使用我的 Git 文件夹作为某种根文件夹:

Must remake target `clean'.
del obj/*.o
CreateProcess(NULL,C:/Program Files/Git/usr/bin/sh.exe -c "del obj/*.o",...)
Putting child 0x006e7fc0 (clean) PID 7234712 on the chain.

这个问题的结论很糟糕。

make 通过 PATH 环境变量查找任何包含 usr/bin 的内容。碰巧因为我也在我的 Windows 10 PC 上安装了 Git,所以 Git 添加了以下文件夹到 PATH:

C:\Program Files\Git\usr\bin

添加带有子字符串 "usr\bin" 的 any 路径将导致 make 尝试 运行 sh 而不是 cmd.exe on Windows.

我的解决方案:从我的 PATH.

中删除 C:\Program Files\Git\usr\bin

更新: 我将名称从 usr\bin 更改为 user\bin,但 make 仍然在该文件夹中找到 sh.exe。最后,我在 Git\usr\bin 文件夹中将 sh.exe 重命名为 _sh.exe

最干净的方法是在命令行中指定 SHELL

make -ftest.mak clean SHELL=cmd

会完成这项工作。 ndk-build 会为您完成,请查看您的 ndk-build.cmd。不要尝试 运行 ndk-build bash Windows 上的脚本。当您在 bash.

中 Windows 上 运行 时,NDK 中的脚本可能会失控