使用我的新Windows 10工作站,我无法构建任何项目,因为由于某种原因,make
无法调用cmd
。该命令通常用于检查目录等中的版本号,并导致构建过程的取消。
请参阅此处有关生成文件的一些片段:
# windows cmd shell
SHELL=$(SYSTEMROOT)/System32/cmd
CC=c:/path/to/compiler
# ...
COMPILER_VALID=FALSE
ifeq ($(DESIRED_VERSION),$(shell "$(CC)"))
COMPILER_VALID=TRUE
endif
ifneq ($(COMPILER_VALID),TRUE)
$(error incorrect compiler version)
endif
# ...
这曾经在我的旧计算机上工作;它仍然像我所有同事一样工作。但是,当我在当前机器上运行make
时,它会生成以下输出:
PS C:UsersBuergerProject> make release
make: C:Windows/System32/cmd: Command not found
buildmakefile.mak:123: *** incorrect compiler version. Stop.
cmd.exe
存在于 C:\Windows\System32\ 中,而 C:\path\to\compiler 是我机器上的有效目录。据我所知,已安装所有必需的开发工具。我在这里错过了什么,为什么我不能构建其他人可以构建的东西的原因是什么?
编辑寻址注释:更改生成文件不是一种选择。make --version
的输出和SYSTEMROOT
的值为
> make --version
GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This program built for i686-pc-cygwin
> echo %SYSTEMROOT%
C:Windows
这是这个Cygwin版本的make的问题。
带有 Cygwin 的 3.81 版似乎错误地扩展了这个 SHELL 变量中的反斜杠。这会导致路径类似于C:Windows/system32/cmd
.
例:
PS C:UsersWDAGUtilityAccountDownloads> Get-Content .Makefile
$(info $(SYSTEMROOT))
SHELL=$(SYSTEMROOT)/system32/cmd
$(info $(shell ver))
PS C:UsersWDAGUtilityAccountDownloads> C:cygwinbinmake.exe
C:Windows
make: C:Windows/system32/cmd: Command not found
make: *** No targets. Stop.
这是一个有效的路径,它是驱动器 C: 中当前工作目录的相对路径,这意味着要使其工作,需要将驱动器 C: 的当前工作目录设置为根驱动器并使用完整路径(或从其他驱动器(调用您的Makefile
。或者,您可以将SHELL
设置更改为仅读取cmd.exe
(不带路径(,以便通过PATH
自动定位它。
但即使在这些情况下,在现代 Windows 上,您也会遇到另一个问题 - 挂起cmd.exe
会话,例如:
PS C:> C:cygwinbinmake.exe -f C:UsersWDAGUtilityAccountDownloadsMakefile -dr
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i686-pc-cygwin
Reading makefiles...
Reading makefile `C:UsersWDAGUtilityAccountDownloadsMakefile'...
C:Windows
<< hanging indefinitely >>
请注意,它不会抱怨 shell,实际上它被定位并运行,但带有-c
开关而不是/c
,导致cmd.exe
在命令后不退出(因此make
将挂起等待(。检查:
PS C:UsersWDAGUtilityAccount> (Get-WmiObject Win32_Process -Filter { Name = 'cmd.exe' }).CommandLine
C:Windowssystem32cmd.exe -c ver
如果您尝试从PowerShell自行运行它,您将看到它将以cmd
结束并且不会返回到PS:
PS C:UsersWDAGUtilityAccount> cmd -c ver
Microsoft Windows [Version 10.0.18362.836]
(c) 2019 Microsoft Corporation. All rights reserved.
C:UsersWDAGUtilityAccount>exit <--- Note command prompt change
PS C:UsersWDAGUtilityAccount>
而不是它应该是什么:
PS C:UsersWDAGUtilityAccount> cmd /c ver
Microsoft Windows [Version 10.0.18362.836]
PS C:UsersWDAGUtilityAccount>
您可以使用.SHELLFLAGS
将-c
替换为/C
,但这是在 make 3.82 中引入的。
底线:我相信你应该使用较新版本的make
。我的第一选择,因为你使用基于cmd
的语法,将是Windows的原生构建(不是Cygwin,不是MinGW(。如果你坚持使用Cygwin,你应该安装最新版本(当前的Cygwinmake
是4.3,它没有这些问题(。请注意,您尝试使用的版本是在 2006 年发布的,此后已实现许多改进(包括基于 Windows 的行为(。