1

I am trying to compile some code that was provided to me using a makefile that was also provided to me. I use MinGW for my compiler on Windows 10.

I have very little experience with makefiles and the makefiles that I have created and ran were no where near as sophisticated as the one I am trying to use to compile some code.

Usually when I compile using a makefile, in command prompt, I go to the directory where the files are located and I just type the command "make" and an executable is created and then I can run the code. However, this time it doesn't work. I get a message that reads:

'make' is not recognized as an internal or external command, operable program or batch file. "

Here is the contents of the make file:

CC=g++
CFLAGS=
INC=
LIB=

all:  sorting

sorting:  Driver.o Helper.o
    $(CC) $(CFLAGS) -o $@ $^ $(LIB)

.cpp.o:
    $(CC) $(CFLAGS) $(INC) -c -o $@ $^ 

Driver.cpp:  Sorting.hpp Helper.cpp

Helper.cpp:  Helper.hpp

clean:
    rm -f *.o sorting

How do I use this make file to run the code?

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
LiveToLearn
  • 163
  • 1
  • 2
  • 12
  • 1
    MinGW-w64 is shipped with mingw32-make.exe, put its bin directory into your path environment variable and then try calling `mingw32-make`. – Benjamin Bihler Feb 18 '19 at 07:33
  • 1
    Please get the formatting of your post right. This is very important, especially for makefile syntac. Make sure that there is no ambiguity of what are blanks and what are tabs, those get lost in the representation here. E.g. state that all leading white space is absolutely always tabs. Then double check that this is actually the case. Then check again. – Yunnosch Feb 18 '19 at 07:33
  • 1
    I did a little improvement of your formatting, but please double check. – Yunnosch Feb 18 '19 at 07:35
  • 1
    How about using CMake? – Mayur Feb 18 '19 at 07:38

4 Answers4

9

MinGW does not provide a Make program called make. It provides GNU Make with the name mingw32-make.exe in the MinGW bin directory, for example C:\MinGW\bin\mingw32-exe.

So to run MinGW's Make program, you must run:

> mingw32-make

and the MinGW bin directory must be in your PATH when you do so.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
2

You can do like the instruction in this link: install and use make in windows

after do like this guide, you can use powerShell in windows to run make command by going to your folder and then select "File > Open Windows PowerShell"

thangpx1706
  • 122
  • 4
1

Install MSYS2 as described here. Run pacman -S make to install make.

As a bonus, MSYS2 provides an up-to-date GCC and a bunch of prebuilt libraries.


There is also mingw32-make, which is a different beast, and should probably be avoided if possible.

The plain make uses sh shell (same as make on Linux), while mingw32-make uses Windows CMD.

This means mingw32-make is unable to run some makefiles, since many of them expect a Linux-like environment.

From my experience, the only thing mingw32-make is good at is running Makefiles generated by CMake (which can generate both make-flavored and mingw32-make-flavored makefiles, depending on flags).

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
-1

my answer comes pretty late. But you got the right answers, MinGW comes not with "make.exe" but with "MinGW-make.exe", and it's not necesary to go to MinGW/bin, it's enoug to add to your path this directory.

Nette Grüße

Wolfgang

Lobito
  • 147
  • 1
  • 1
  • 7
  • This is the same solution as in [Mike's answer](https://stackoverflow.com/a/54742808/2227743). *When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.* – Eric Aya Oct 28 '21 at 14:07