How to compile makefile using MinGW?
Asked Answered
H

9

81

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.

Haber answered 2/8, 2012 at 7:7 Comment(6)
Of course not, you shouldn't put anything in mingw\bin. What is your exact problem? (i.e. explain what is failing for you.)Witchery
If you have a Makefile.am, then I suggest you read more about automake and autoconf.Rattlebox
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.Haber
Do you have mingw32-make.exe installed?Coastguardsman
yes, i've already installed it.Haber
I solved it renaming MinGW\bin\mingw32-make.exe into MinGW\bin\make.exeDanelle
C
57

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.

Coastguardsman answered 2/8, 2012 at 10:32 Comment(4)
just installed mingw and I have neither in bin folder.Phalanger
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!Cesaria
@Phalanger make sure you installed correct version, you can try: this link ,this works for me, with gcc and gdb 8.1Saltine
That FAQ link didn't work for me, so I used sourceforge.net/p/mingw-w64/wiki2/FAQWorkingman
P
14

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.

Periodic answered 13/8, 2015 at 11:41 Comment(1)
Use Cmake for windows to generate the makefiles. cd to the directory and use mingw32-make.exe.Wallflower
F
7

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.

Filibertofilibuster answered 16/4, 2020 at 12:28 Comment(1)
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.Airlie
A
3

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

Amelita answered 23/11, 2020 at 20:49 Comment(1)
tnx, that helped a lotBurkholder
R
2

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

Rockyrococo answered 21/7, 2023 at 23:5 Comment(0)
S
1

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)
Slaty answered 20/1, 2020 at 10:25 Comment(1)
facepalm. You don't compile a makefile by writing another oneLudeman
S
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

Saito answered 12/4, 2023 at 14:31 Comment(0)
N
0

11 years later...

Download from Source Forge Open MinGW Installer Select Basic Setup,

navigate to Packages and Right click on “mingw-developer-toolkit-bin”, “mingw32-base-bin” and “msys-base-bin” Packages and select Mark for Installation

Navigate to the Top left corner and Left click on Installation then click Apply Changes

Make a coffee..

Add C:\MinGW\bin to the system PATH *** ALSO Add "C:\MinGW\msys\1.0\bin" ***

Apparently the file structure has changed but none of the documentation seems to have been updated. So the msys path needs to be added too now. That's two hours I'm not getting back!

Most of this is in https://nerdyelectronics.com/install-mingw-on-windows-for-make/ and the answers above, but adding the second PATH is the secret sauce

Northway answered 14/1 at 0:10 Comment(0)
O
-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/

Ortego answered 2/8, 2012 at 8:53 Comment(2)
Thats mean i can only compile the file using automake?Haber
This link has no information that would help solve the user's problem without significant digging.Whose

© 2022 - 2024 — McMap. All rights reserved.