我正在遵循某人的指示,我将其存储库克隆到我的机器上。我想使用make命令作为设置代码环境的一部分,但我使用的是Windows。我在网上搜索了一下,但只找到了一个make.exe文件、一个make. 4.1.tar.gz文件(我不知道接下来该怎么处理它)和如何下载MinGW(适用于GNU;但安装后,我没有发现任何提到“make”)。

在没有GNU编译器或相关包的情况下,如何使用Windows中的make ?


make是一个GNU命令,所以在Windows上获得它的唯一方法是安装一个像GNUWin32提供的Windows版本。不管怎样,有几个选项可以得到它:

The most simple choice is using Chocolatey. First you need to install this package manager. Once installed you simlpy need to install make (you may need to run it in an elevated/admin command prompt) : choco install make Other recommended option is installing a Windows Subsystem for Linux (WSL/WSL2), so you'll have a Linux distribution of your choice embedded in Windows 10 where you'll be able to install make, gccand all the tools you need to build C programs. For older Windows versions (MS Windows 2000 / XP / 2003 / Vista / 2008 / 7 with msvcrt.dll) you can use GnuWin32.

一个过时的替代方案是MinGw,但这个项目似乎已经被放弃了,所以最好还是选择以前的一个选择。


一般来说,接受的答案是一个坏主意,因为手动创建的make.exe会一直存在,并可能导致意想不到的问题。它实际上破坏了RubyInstaller: https://github.com/oneclick/rubyinstaller2/issues/105

另一种选择是通过Chocolatey安装make(正如@Vasantha Ganesh K指出的那样)

另一种方法是在Chocolatey上安装MSYS2,在C:\tools\msys64\usr\bin中使用make。如果make没有在MSYS2中自动安装,你需要通过pacman -S make手动安装(正如@Thad Guidry和@Luke指出的那样)。


安装Msys2 http://www.msys2.org 遵循安装说明 使用$ pacman -S make gettext base-devel安装make 添加C:\msys64\usr\bin\到您的路径


从他们的官方网站GnuWin32下载make.exe

在下载会话中,单击 完整的包,除了源代码。 按照安装说明安装。 完成后,将<安装目录>/bin/添加到PATH变量中。

现在您将能够在cmd中使用make。


GNU make可用于巧克力。

从这里安装chocoley。 然后,choco安装make。

现在您将能够在窗口上使用Make。 我试着在MinGW上使用它,但它应该也能在CMD上工作。


如果你使用的是Windows 10,它是内置在Linux子系统特性中的。只需要启动一个Bash提示符(按Windows键,然后输入Bash并选择“Bash on Ubuntu on Windows”),cd到你想要制作的目录并输入make。

FWIW, Windows驱动器在/mnt中找到,例如Bash中的C:\ drive是/mnt/ C。

如果Bash在开始菜单中不可用,下面是打开Windows功能(仅限64位Windows)的说明:

https://learn.microsoft.com/en-us/windows/wsl/install-win10


另一种选择是,如果你已经安装了minGW,并添加了bin文件夹的to Path环境变量,你可以使用“mingw32-make”而不是“make”。

你也可以创建一个从"make"到"mingw32-make"的符号链接,或者复制并更改文件名。我不推荐之前的选项,他们会工作,直到你对minGW做改变。


我可以建议循序渐进的方法。

Visit GNUwin Download the Setup Program Follow the instructions and install GNUWin. You should pay attention to the directory where your application is being installed. (You will need it later1) Follow these instructions and add make to your environment variables. As I told you before, now it is time to know where your application was installed. FYI: The default directory is C:\Program Files (x86)\GnuWin32\. Now, update the PATH to include the bin directory of the newly installed program. A typical example of what one might add to the path is: ...;C:\Program Files (x86)\GnuWin32\bin


如果你想使用命令行模拟器cder,一个解决方案可能会有帮助。您可以随意地安装包安装程序。首先,我们在windows命令提示符中使用以下行安装chocately:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
refreshenv

在安装了chocolatey之后,可以使用choco命令来安装make。安装完成后,你需要在/ cder /config/user_alias .cmd中添加一个别名。应增加以下一行:

make="path_to_chocolatey\chocolatey\bin\make.exe" $*

然后,Make将在cmder环境中操作。


Install npm install Node Install Make node install make up node install make If above commands displays any error then install Chocolatey(choco) Open cmd and copy and paste the below command (command copied from chocolatey URL) @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"


我也曾经遇到过同样的问题。但我很惊讶没有找到一个特解。

从GnuWin32或通过winget安装是很好的和简单的选择。但我只找到了3.8.1。这个版本缺少非常重要的选项-O,它在编译多线程时正确地处理输出。

目前,Choco似乎提供4.3。所以我们可以期待最近的版本。

但是也有自编译的选项。如果你必须安装make(用于编译),这应该是一个有效的选项。

head to https://www.gnu.org/software/make/ and download a version of your liking unpack the tar.gz files (use 7zip and unpack the file twice to retrieve the actual content) navigate to the created directory open command prompt in that directory run build_w32.bat gcc This will start the compilation with the gcc compiler, which you would need to install in advance. When running build_w32.bat without any option they try to use the MSVC compiler. Sidenote: I found it surprising that gnu does not use gcc as default but MSVC :-) ignore the warnings created during compilation. The result should still be fine retrieve your fresh gnumake.exe from the directoy GccRel (when compiled with gcc) put this file somewhere where you like and rename to make.exe add the location to the system variable %PATH%

正如其他人所指出的:如果其他程序也安装了各种make版本,那么这种手动安装可能会导致冲突。


除了GNU之外,您可能还需要许多coreutils。Touch, rm, cp, sed, test, tee, echo等等。构建系统可能需要bash特性,如果没有其他原因,通常从进程ID($$$$)创建临时文件名。没有bash是不行的。你可以用Windows上流行的POSIX模拟器得到所有东西:

Cygwin (http://www.cygwin.org/) Probably the most popular one and the most compatible with POSIX. Has some difficulties with Windows paths and it's slow. GNUWin (http://gnuwin32.sourceforge.net/) It was good and fast but now abandoned. No bash provided, but it's possible to use it from other packages. ezwinports (https://sourceforge.net/projects/ezwinports) My current favorite. Fast and works well. There is no bash provided with it, that can be a problem for some build systems. It's possible to use make from ezwinports and bash from Cygwin or MSYS2 as a workaround. MSYS 1.19 abandoned. Worked well but featured very old make (3.86 or so) MSYS2 (https://www.msys2.org/) Works well, second fastest solution after ezwinports. Good quality, package manager (pacman), all tooling available. I'd recommend this one. MinGW abandoned? There was usually MSYS 1.19 bundled with MinGW packages, that contained an old make.exe. Use mingw32-make.exe from the package, that's more up to date.

Note that you might not be able to select your environment. If the build system was created for Cygwin, it might not work in other environments without modifications (The make language is the same, but escaping, path conversion are working differently, $(realpath) fails on Windows paths, DOS bat files are started as shell scripts and many similar issues). If it's from Linux, you might need to use a real Linux or WSL. If the compiler is running on Linux, there is no point in installing make for Windows, because you'll have to run both make and the compiler on Linux. In the same way, if the compiler is running on Windows, WSL won't help, because in that environment you can only execute Linux tools, not Windows executables. It's a bit tricky!


你也可以安装scoop,然后运行:

scoop install make

在windows 10或windows 11操作系统上执行winget install GnuWin32命令。在命令行或powershell中进行Make以快速安装。然后可以使用cmake命令。

没有必要再安装巧克力了。