285

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?

0x6B6F77616C74
  • 2,480
  • 7
  • 34
  • 64
Kim
  • 2,861
  • 2
  • 15
  • 4
  • 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 '10 at 08:13
  • 3
    Very clear guide is given [here](https://www.youtube.com/watch?v=hh-V6el8Oxk) – Scott Mar 04 '20 at 06:04
  • Possible duplicate of https://stackoverflow.com/questions/32127524/how-to-install-and-use-make-in-windows – tripleee Sep 18 '21 at 16:43

17 Answers17

146

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.

ledawg
  • 1,736
  • 1
  • 10
  • 16
  • 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. – Tumo Masire Apr 27 '21 at 13:44
  • This is the best way to use make in windows, with no complication. And working fine for my team. – Lakshay Rohilla May 16 '22 at 09:15
142

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.

Marcelo Cantos
  • 174,413
  • 38
  • 319
  • 360
  • 7
    How do I run the visual studio command prompt from the start menu? – Kim Mar 28 '10 at 07:54
  • Alright I figured it out. But of course it wouldn't compile because of errors. Just my luck. Thanks though. – Kim Mar 28 '10 at 08:20
  • 12
    For those with VS2012, the command prompt is called "Developer Command Prompt for VS2012". Start--> Search--> "command" is how I found it. – undeniablyrob Apr 17 '13 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](http://www.microsoft.com/visualstudio/eng/downloads#d-2012-express) suffices. – Marcelo Cantos Jun 06 '13 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 '13 at 11:04
  • @Cheeku: That's a different question and has little to do with programming. Why don't you just install it from whatever package manager your Linux distro has? – Marcelo Cantos Jun 11 '13 at 11:25
  • @MarceloCantos How to do it on Windows? Not using cygwin or GNU Make, instead using VS Developer Command Prompt – Cheeku Jun 11 '13 at 15:23
  • Great! how do I make nmake callabre from Windows console? just edit path variable so that it find the executable? – The Mask May 28 '14 at 11:25
  • @TheMask: That's explained in the answer. – Marcelo Cantos May 29 '14 at 10:28
  • What about for those of us that don't have it in the start menu? navigating to the MSVS cmd prompt via the start menu is not a valid answer. I don't know the exact command it executes, but all that thing in the start menu is a shortcut to some executable with a few command line switches - none of which I remember - all of which I want to know what they are. The start menu can't help everyone – searchengine27 Jun 08 '15 at 21:33
  • I obtained a copy of MSVS 2010 C++, and this is what the command line was for that shortcut '%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86'. This isn't quite what I remember, but either way, there it is. It looks like in this case all its doing is setting up the environment for a regular shell – searchengine27 Jun 08 '15 at 21:40
  • @searchengine27: Afaict, it was a valid answer five years ago. – Marcelo Cantos Jun 09 '15 at 10:18
  • @MarceloCantos No, it was never a valid answer. Unless you're saying that the "MSVS Command Prompt" was its own individual executable, and that MSVS mandated that you always have that in the start menu (both of which I know for a fact are not true), then that was never a valid answer. Other people happening to have it in the start menu because they/their company installed it in such a fashion does not correlate to this being a valid answer. It is a helpful answer to some people, but you're confusing that with valid to the question. I suggest updating your answer to make it valid. – searchengine27 Jun 09 '15 at 14:40
  • @searchengine27: It's a valid answer for anyone installing the product in the standard way. It has always been there for me, even in corporate environments. If some enterprise IT shop wants to do weird shit, that's their business. – Marcelo Cantos Jun 10 '15 at 09:21
  • If your makefile contains Linux commands as well, you cannot use this approach, you need Cygwin. – jciloa Feb 02 '19 at 08:39
  • In my case, making file for libjpeg in windows, i needed for win32.mak file, you can find it at: "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\Win32.Mak" – Ing. Gerardo Sánchez Oct 27 '19 at 16:13
68

Check out cygwin, a Unix alike environment for Windows

Frank
  • 2,236
  • 17
  • 16
  • 7
    cygwin worked well for me!. I just had to check, during installation, some packages in `Devel` : 'make' and also 'gcc' as explained [here](http://stackoverflow.com/questions/4828388/cygwin-make-bash-command-not-found). – Damien Leroux Apr 16 '16 at 15:09
  • 12
    I also recommend to install cygwin using chocolatey, so the command to get `make` is this: `choco install make --source=cygwin` – zygimantus May 21 '18 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 '18 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" – Ali.Ghodrat Nov 01 '18 at 13:08
61

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
KyleMit
  • 35,223
  • 60
  • 418
  • 600
Sean Lynch
  • 6,027
  • 2
  • 41
  • 45
  • 13
    In addition, please add "C:\Program Files (x86)\GnuWin32\bin" to your system PATH. – ccy Oct 06 '18 at 07:16
  • You also might want to consider changing the install directory to avoid spaces and parenthesis as they can [cause issues running the CLI](https://stackoverflow.com/q/15080184/1366033) – KyleMit Dec 05 '20 at 20:08
36

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

Maria Ines Parnisari
  • 15,351
  • 7
  • 80
  • 120
alan9uo
  • 871
  • 9
  • 15
  • 14
    It's probably better to add `bin` directory to `PATH` environment variable. This will make `make.exe` available from anywhere. – Yukulélé Jul 21 '18 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 05 '18 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 06 '19 at 20:18
  • Work like a champ – trungducng Jun 11 '20 at 08: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
sunny0402
  • 91
  • 1
  • 2
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.

binary robot
  • 83
  • 1
  • 4
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

Jón Trausti Arason
  • 4,195
  • 1
  • 33
  • 45
6

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.

WENDYN
  • 502
  • 6
  • 13
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

ap-osd
  • 2,224
  • 15
  • 16
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.

Validus Oculus
  • 2,384
  • 1
  • 21
  • 31
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

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.

Liam Kernighan
  • 1,894
  • 1
  • 18
  • 21
  • 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. – Jaime Herrera May 19 '22 at 03: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)
Amit Kumar
  • 939
  • 9
  • 6
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.

Anatoly
  • 15,836
  • 3
  • 19
  • 33
0

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.

Lovish Garg
  • 69
  • 2
  • 8
-9

May be it can work.

pip install Makefile
Nikhil Parashar
  • 390
  • 4
  • 11