353

I have some demos that I downloaded and they come with a Makefile.win and a Makefile.sgi. How can I run these in Windows to compile the demos?

8
  • 5
    I should mention that I'm more of a Linux person but I need to use Windows right now, so I'm a little clueless.
    – Kim
    Mar 28, 2010 at 8:13
  • 4
    Very clear guide is given here
    – Scott
    Mar 4, 2020 at 6:04
  • Possible duplicate of stackoverflow.com/questions/32127524/…
    – tripleee
    Sep 18, 2021 at 16:43
  • 1
    @tripleee how should we consider which is the dupe of which, here though? This question is from 2010, while the other, even if similarly votes, is from 2015. Nov 8, 2022 at 11:16
  • 1
    @β.εηοιτ.βε The age of the duplicate is unimportant; the general rule is to take the better question, and/or the one with better answers, and make that the canonical.
    – tripleee
    Nov 8, 2022 at 11:21

22 Answers 22

236

You can install GNU make with chocolatey, a well-maintained package manager, which will add make to the global path and runs on all CLIs (powershell, git bash, cmd, etc…) saving you a ton of time in both maintenance and initial setup to get make running.

  1. Install the chocolatey package manager for Windows
    compatible to Windows 7+ / Windows Server 2003+

  2. Run choco install make

I am not affiliated with choco, but I highly recommend it, so far it has never let me down and I do have a talent for breaking software unintentionally.

2
  • 3
    You are amazing, thanks so much. Runs as if trying the Makefile on a native Linux environment, but in windows! Was having issues with make using WSL, for a gui Java app, but this made it work using PowerShell. Apr 27, 2021 at 13:44
  • This is the best way to use make in windows, with no complication. And working fine for my team. May 16, 2022 at 9:15
152

If you have Visual Studio, run the Visual Studio Command prompt from the Start menu, change to the directory containing Makefile.win and type this:

nmake -f Makefile.win

You can also use the normal command prompt and run vsvars32.bat (c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools for VS2008). This will set up the environment to run nmake and find the compiler tools.

16
  • 8
    How do I run the visual studio command prompt from the start menu?
    – Kim
    Mar 28, 2010 at 7:54
  • Alright I figured it out. But of course it wouldn't compile because of errors. Just my luck. Thanks though.
    – Kim
    Mar 28, 2010 at 8:20
  • 12
    For those with VS2012, the command prompt is called "Developer Command Prompt for VS2012". Start--> Search--> "command" is how I found it. Apr 17, 2013 at 20:41
  • @NSD: You can try other "make"s, but such files are usually written against nmake's dialect and with the assumption that VS is installed and on the path. You might find that the free VS Express suffices. Jun 6, 2013 at 21:01
  • 2
    @MarceloCantos I am a noob to Linux and Making. What if I have .am and .mk file. I don't have any .win file. I am trying to make wget, btw.
    – Cheeku
    Jun 11, 2013 at 11:04
79

Check out GnuWin's make (for windows), which provides a native port for Windows (without requiring a full runtime environment like Cygwin)

If you have winget, you can install via the CLI like this:

winget install GnuWin32.Make

Also, be sure to add the install path to your system PATH:

C:\Program Files (x86)\GnuWin32\bin
4
  • 13
    In addition, please add "C:\Program Files (x86)\GnuWin32\bin" to your system PATH.
    – ccy
    Oct 6, 2018 at 7:16
  • You also might want to consider changing the install directory to avoid spaces and parenthesis as they can cause issues running the CLI
    – KyleMit
    Dec 5, 2020 at 20:08
  • I tried today on Win10, and I didn't need to add it to path.... Works! Maybe WinGet is smarter now?
    – Joe DF
    Jan 19, 2023 at 2:52
  • 2
    It no longer finds the Make. winget install GnuWin32.Make No package found matching input criteria. It does see other GnuWin32 packages when doing winget search GnuWin32 Mar 5 at 17:23
69

Check out cygwin, a Unix alike environment for Windows

4
  • 7
    cygwin worked well for me!. I just had to check, during installation, some packages in Devel : 'make' and also 'gcc' as explained here. Apr 16, 2016 at 15:09
  • 14
    I also recommend to install cygwin using chocolatey, so the command to get make is this: choco install make --source=cygwin
    – zygimantus
    May 21, 2018 at 13:15
  • after I installed with choco, how can I add it to my command shell? there is a path to be added?
    – XaBerr
    Aug 21, 2018 at 20:25
  • 4
    In case you installed it with choco, then add this line (witought quotation marks) to your path variable in the system variables "C:\tools\cygwin\bin" Nov 1, 2018 at 13:08
42

Here is my quick and temporary way to run a Makefile

  • download make from SourceForge: gnuwin32
  • install it
  • go to the install folder

C:\Program Files (x86)\GnuWin32\bin

  • copy the all files in the bin to the folder that contains Makefile

libiconv2.dll libintl3.dll make.exe

  • open the cmd (you can do it with right click with shift) in the folder that contains Makefile and run

make.exe

done.

Plus, you can add arguments after the command, such as

make.exe skel

4
  • 18
    It's probably better to add bin directory to PATH environment variable. This will make make.exe available from anywhere.
    – Yukulélé
    Jul 21, 2018 at 21:09
  • 1
    I think its done by default - at least that was the case when I installed gnuwin32. Of course copying the files is bad practice anyway.
    – JFFIGK
    Aug 5, 2018 at 15:54
  • 1
    It is not done by default (or not in my case). By adding it to the path, then you can run make from the project folder.
    – Victor
    Feb 6, 2019 at 20:18
  • Work like a champ
    – trungducng
    Jun 11, 2020 at 8:04
9

If you install Cygwin. Make sure to select make in the installer. You can then run the following command provided you have a Makefile.

make -f Makefile

https://cygwin.com/install.html
9

I use MinGW tool set which provides mingw32-make build tool, if you have it in your PATH system variables, in Windows Command Prompt just go into the directory containing the files and type this command:

mingw32-make -f Makefile.win

and it's done.

1
  • 1
    could copy a {mingw64 folder}/bin/mingw32-make.exe and rename it to make.exe
    – Rohim Chou
    Dec 8, 2022 at 15:43
8

I tried all of the above. What helps me:

  1. Download the mingw-get.
  2. Setup it.
  3. Add something like this C:\MinGW\bin to environment variables.
  4. Launch (!important) git bash. Power shell, developer vs cmd, system cmd etc didn't help.
  5. Type mingw-get into the command line.
  6. After type mingw-get install mingw32-make.

Done! Now You might be able to use make-commands from any folder that contains Makefile.

0
6

With Visual Studio 2017 I had to add this folder to my Windows 10 path env variable:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64

There's also HostX86

4

If it is a "NMake Makefile", that is to say the syntax and command is compatible with NMake, it will work natively on Windows. Usually Makefile.win (the .win suffix) indicates it's a makefile compatible with Windows NMake. So you could try nmake -f Makefile.win.

Often standard Linux Makefiles are provided and NMake looks promising. However, the following link takes a simple Linux Makefile and explains some fundamental issues that one may encounter. It also suggests a few alternatives to handling Linux Makefiles on Windows.

Makefiles in Windows

3

Firstly, add path of visual studio common tools (c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools) into the system path. To learn how to add a path into system path, please check this website: http://www.computerhope.com/issues/ch000549.htm. You just need to this once.

After that, whenever you need, open a command line and execute vsvars32.bat to add all required visual studio tools' paths into the system path.

Then, you can call nmake -f makefile.mak

PS: Path of visual studio common tools might be different in your system. Please change it accordingly.

3

I tried with cygwin & gnuwin, and didn't worked for me, I guess because the makefile used mainly specific linux code.

What it worked was use Ubuntu Bash for Windows 10. This is a Marvel if you come from MAC as it is my case:

  1. To install the Ubuntu Bash: https://itsfoss.com/install-bash-on-windows/
  2. Once in the console, to install make simply type "make" and it gives the instructions to download it.

Extras:

  1. Useful enable copy / paste on bash: Copy Paste in Bash on Ubuntu on Windows
  2. In my case the make called Maven, so I have to install it as well: https://askubuntu.com/questions/722993/unable-to-locate-package-maven
  3. To access windows filesystem C: drive, for example: "cd /mnt/c/"

Hope it helps

3

If you have already installed the Windows GNU compiler (MinGW) from MSYS2 then make command comes pre-installed as wingw32-make. Always match cmake makefile generation with the correct make command. Mixing these generate problems.

MinGW makefile generation with MinGW make command

Visual Studio makefile generation with VS equivalent make command

And this is always possible as long as you have the source code. Just delete old build directory and start over by specifying this time the right parameter in cmake ,e.g.

mkdir build
cd build
cmake -G "MinGW MakeFiles" path/to/src/whereCMakeLists.txtInstructionsAre   
mingw32-make     
myProject.exe   # RUN

I have encountered issues during compilation where multiple make commands interact. To prevent this just edit/remove the environmental variables that lead to different make commands. For example to prevent conflicts with mingw, keep only C:\msys64\mingw64\bin but remove C:\msys64\usr\bin. That other path contains the msys make and as I said you do not want to combine make commands during compilation.

2

Install msys2 with make dependency add both to PATH variable. (The second option is GNU ToolChain for Windows. MinGW version has already mingw32-make included.)

Install Git Bash. Run mingw32-make from Git Bash.

1
  • 1
    Thanks, this was the perfect solution for my environment. I am learning how to minimally compile big projects in Windows' VS Code with make (like I do in Linux with boost-build), but I kept struggling with cmd and Windows shell syntax. May 19, 2022 at 3:23
1
  1. Download from https://sourceforge.net/projects/gnuwin32/
  2. Set the variable path in advance setting for recognize in command prompt (C:\Program Files (x86)\GnuWin32\bin)
1

So if you're using Vscode and Mingw then you should first make sure that the bin folder of the mingw is included in the environment path and it is preferred to change the mingw32-make.exe to make to ease the task and then create a makefile and include this code in it .

all:
    gcc -o filename filename.c
    ./filename

Then save the makefile and open Vscode Code terminal and write make. Then makefile will get executed.

1
  • Following this tutorial helps alot with the setup as well
    – kyrlon
    Dec 21, 2022 at 13:53
1

The procedure I followed is;

  1. I installed Gnuwin32's make using the installable.
  2. Added the "make" path to the environmental variable PATH.
  3. Verified the installation using "make --version"
1
  • This seems to be yet another duplicate of multiple existing answers from the previous decades.
    – tripleee
    Nov 10, 2022 at 11:59
1

You can also install via the Scoop package manager (similar to Chololatey). Go to Scoop and search for the package you need. In this case make and paste the command for installing it.

Command to install make on Windows. I tested in PowerShell.

scoop install main/make
0

I am assuming you added mingw32/bin is added to environment variables else please add it and I am assuming it as gcc compiler and you have mingw installer.

First step: download mingw32-make.exe from mingw installer, or please check mingw/bin folder first whether mingw32-make.exe exists or not, else than install it, rename it to make.exe.

After renaming it to make.exe, just go and run this command in the directory where makefile is located. Instead of renaming it you can directly run it as mingw32-make.

After all, a command is just exe file or a software, we use its name to execute the software, we call it as command.

0

For me installing ubuntu WSL on windows was the best option, that is the best tool for compiling makefile on windows. One thousand is better than Cygwin64, because to compile a makefile you will need another package and compile software like maybe gfortran, netcdf, etc, ect, in ubuntu WSL you can install all of these packages very easily and quickly ;)

1
  • Just WSL is a good start, but not by itself enough. On Debian-based platforms (such as Ubuntu), apt-get install -y build-essential will get you a build toolchain which works for many projects, including creating new Debian packages.
    – tripleee
    Oct 14, 2022 at 15:43
-1

Go to http://gnuwin32.sourceforge.net/packages/make.htm and download make-3.81.exe, install and add to Windows path.

1
  • This seems to duplicate Sean's answer from 2013.
    – tripleee
    Jul 26, 2022 at 17:09
-12

May be it can work.

pip install Makefile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.