331

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,559
  • 7
  • 38
  • 65
Kim
  • 3,321
  • 2
  • 16
  • 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
  • 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 08 '22 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 08 '22 at 11:21
  • Also, none of the answers here seem to adequately explain that installing `make` is a very small problem compared to actually making a Makefile work correctly on a new platform. `Makefile.sgi` sounds like something was very specific to a historic Unix platform (SGI / Irix). – tripleee Nov 08 '22 at 11:24
  • @tripleee mhm, hard one then. IMO, the other question looks indeed better worded to me, but the highest score answer here looks better written. – β.εηοιτ.βε Nov 08 '22 at 11:53
  • If one is closed as a duplicate of the other, you can request a mod to merge them. But so far I have not done that. – tripleee Nov 08 '22 at 11:57

22 Answers22

212

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
  • 2,395
  • 1
  • 11
  • 17
  • 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
151

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
  • 181,030
  • 38
  • 327
  • 365
  • 8
    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
72

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
  • 30,350
  • 66
  • 462
  • 664
Sean Lynch
  • 6,267
  • 2
  • 43
  • 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
  • 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 '23 at 02:52
69

Check out cygwin, a Unix alike environment for Windows

Frank
  • 2,375
  • 1
  • 19
  • 17
  • 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
  • 13
    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
40

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
  • 16,584
  • 9
  • 85
  • 130
alan9uo
  • 1,011
  • 1
  • 11
  • 17
  • 17
    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
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.

WENDYN
  • 650
  • 7
  • 15
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,548
  • 1
  • 39
  • 46
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,624
  • 16
  • 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,756
  • 1
  • 25
  • 34
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.

Liam Kernighan
  • 2,335
  • 1
  • 21
  • 24
  • 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. – 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
  • 1,503
  • 14
  • 11
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.

Lovish Garg
  • 79
  • 2
  • 8
  • Following this [tutorial](https://code.visualstudio.com/docs/cpp/config-mingw) helps alot with the setup as well – kyrlon Dec 21 '22 at 13:53
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
  • 20,799
  • 3
  • 28
  • 42
Bheem
  • 21
  • 2
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 ;)

  • 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 '22 at 15:43
0

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"
Bhuvan
  • 370
  • 9
0

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
tripleee
  • 175,061
  • 34
  • 275
  • 318
Felipe Illanes
  • 419
  • 5
  • 8
-1

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

Merzouk MENHOUR
  • 107
  • 1
  • 5
-12

May be it can work.

pip install Makefile
Nikhil Parashar
  • 431
  • 5
  • 11