76

I'm new to this. Just wanted to ask how to compile a makefile. I am using MinGW compiler in C language. Do I have to save all my files in MinGW\bin? because right now my files are in a different directory.

Appreciate the help.

Mefitico
  • 816
  • 1
  • 12
  • 41
AAA
  • 811
  • 2
  • 7
  • 7
  • 1
    Of course not, you shouldn't put _anything_ in mingw\bin. What is your exact problem? (i.e. explain what is failing for you.) – Mat Aug 02 '12 at 07:10
  • 1
    If you have a Makefile.am, then I suggest you read more about [automake](http://www.gnu.org/software/automake/) and [autoconf](http://www.gnu.org/software/autoconf/). – Some programmer dude Aug 02 '12 at 07:12
  • ok, i have a project in C that my supervisor ask me to compile. that project are containing a makefile.in and also makefile.in. Which i have 0 knowledge about. after research, i have manage to install MinGW compiler. I have also change the variable environment and the directory in the command prompt directing to the file location. Now, can anyone tell me how to compile the project?really appreciate it. – AAA Aug 02 '12 at 08:15
  • Do you have mingw32-make.exe installed? – askmish Aug 02 '12 at 10:23
  • yes, i've already installed it. – AAA Aug 03 '12 at 00:46
  • 4
    I solved it renaming MinGW\bin\mingw32-make.exe into MinGW\bin\make.exe – richar8086 Apr 08 '17 at 11:48

8 Answers8

52

Excerpt from http://www.mingw.org/wiki/FAQ:

What's the difference between make and mingw32-make?

The "native" (i.e.: MSVCRT dependent) port of make is lacking in some functionality and has modified functionality due to the lack of POSIX on Win32. There also exists a version of make in the MSYS distribution that is dependent on the MSYS runtime. This port operates more as make was intended to operate and gives less headaches during execution. Based on this, the MinGW developers/maintainers/packagers decided it would be best to rename the native version so that both the "native" version and the MSYS version could be present at the same time without file name collision.

So,look into C:\MinGW\bin directory and first make sure what make executable, have you installed.(make.exe or mingw32-make.exe)

Before using MinGW, you should add C:\MinGW\bin; to the PATH environment variable using the instructions mentioned at http://www.mingw.org/wiki/Getting_Started/

Then cd to your directory, where you have the makefile and Try using mingw32-make.exe makefile.in or simply make.exe makefile.in(depending on executables in C:\MinGW\bin).

If you want a GUI based solution, install DevCPP IDE and then re-make.

askmish
  • 6,464
  • 23
  • 42
  • 22
    just installed mingw and I have neither in bin folder. – ecoe Feb 10 '15 at 22:22
  • 11
    `mingw32-make` hasn't been around for years! Outdated and deprecated, and MinGW repo URLs are a mess to navigate, they just leave old repos and urls around, that haven't been used for years. Be aware! – not2qubit Dec 14 '18 at 08:50
  • @ecoe make sure you installed correct version, you can try: [this link](http://mingw-w64.org/doku.php/download/mingw-builds/) ,this works for me, with gcc and gdb 8.1 – H3d9 Jul 06 '20 at 17:45
  • 2
    That FAQ link didn't work for me, so I used https://sourceforge.net/p/mingw-w64/wiki2/FAQ/ – Doug Null Apr 05 '21 at 18:09
12

You have to actively choose to install MSYS to get the make.exe. So you should always have at least (the native) mingw32-make.exe if MinGW was installed properly. And if you installed MSYS you will have make.exe (in the MSYS subfolder probably).

Note that many projects require first creating a makefile (e.g. using a configure script or automake .am file) and it is this step that requires MSYS or cygwin. Makes you wonder why they bothered to distribute the native make at all.

Once you have the makefile, it is unclear if the native executable requires a different path separator than the MSYS make (forward slashes vs backward slashes). Any autogenerated makefile is likely to have unix-style paths, assuming the native make can handle those, the compiled output should be the same.

jiggunjer
  • 1,905
  • 1
  • 19
  • 18
  • 1
    Use Cmake for windows to generate the makefiles. cd to the directory and use mingw32-make.exe. –  Nov 25 '20 at 06:13
6

I have MinGW and also mingw32-make.exe in my bin in the C:\MinGW\bin . same other I add bin path to my windows path. After that I change it's name to make.exe . Now I can Just write command "make" in my Makefile direction and execute my Makefile same as Linux.

  • Do I have to save all my files in MinGW\bin? Don't, let your source code-files where they are, what you are to do, is to add this directory to the "path"-variable in Windows-path and this is what you already did. – Lobito Oct 24 '21 at 14:31
2

First check if mingw32-make is installed on your system. Use mingw32-make.exe command in windows terminal or cmd to check, else install the package mingw32-make-bin.

then go to bin directory default ( C:\MinGW\bin) create new file make.bat

@echo off
"%~dp0mingw32-make.exe" %*

add the above content and save it

set the env variable in powershell

$Env:CC="gcc"

then compile the file

make hello

where hello.c is the name of source code

Suman Saurabh
  • 401
  • 5
  • 9
0

I found a very good example here: https://bigcode.wordpress.com/2016/12/20/compiling-a-very-basic-mingw-windows-hello-world-executable-in-c-with-a-makefile/

It is a simple Hello.c (you can use c++ with g++ instead of gcc) using the MinGW on windows.

The Makefile looking like:

EXECUTABLE = src/Main.cpp

CC = "C:\MinGW\bin\g++.exe"
LDFLAGS = -lgdi32

src = $(wildcard *.cpp)
obj = $(src:.cpp=.o)

all: myprog

myprog: $(obj)
    $(CC) -o $(EXECUTABLE) $^ $(LDFLAGS)

.PHONY: clean
clean:
    del $(obj) $(EXECUTABLE)
user3742309
  • 183
  • 2
  • 12
0

The easiest way to install make for MinGW that I found is

  • Go to ezwinports
  • Download file make-4.3-without-guile-w32-bin.zip (get the version without guile)
  • Extract zip
  • Copy the contents to your Git/mingw64/ directory, merging the folders, but do NOT overwrite/replace any existing files
  • navigate to the Git/mingw64/ directory via $(cd /; explorer .)

See https://www.pascallandau.com/blog/setting-up-git-bash-mingw-msys2-on-windows/#how-to-install-make for a short video of the process

Hirnhamster
  • 7,101
  • 8
  • 43
  • 73
0

I had to run pacman -S make to get the make executable.

Rami Alloush
  • 2,308
  • 2
  • 27
  • 33
-1

Please learn about automake and autoconf.

Makefile.am is processed by automake to generate a Makefile that is processed by make in order to build your sources.

http://www.gnu.org/software/automake/

lu_zero
  • 978
  • 10
  • 14