Franz Beckenbauer
Franz Beckenbauer

Reputation: 31

How to make 'make' work with mingw32 on Windows 7

I'm pretty new to C and to programming so I hope you guys have a little patience. However I try to describe my problem as precise as possible. I'm using mingw32 on my Windows 7 computer and I just learned about 'make'. I have written some source-code files and a Makefile. What I want is, that the Makefile compiles my source-code int object code and then link it together to one executable (I guess that's nothing wild for a pro).

So here is my code:

first.c:

#include<stdio.h>
#include"second.h"
int main()
{
float x = 12.0;
printf("Result is: %.2f\n",go_to_the_other(x));
return 0;
}

second.h

float go_to_the_other(float f);

second.c

float go_to_the_other(float f)
{
float calc = f + 10;
return calc;
}

And the Makefile is (and yes, I used only tabs):

second.o: second.c second.h
        gcc   -c   second.c
first.o:    first.c
        gcc   -c   first.c
first:   first.o  second.o
        gcc first.o second.o  -o first

This is just an easy example, but it pretty much describes my problem. I have all files in the same directory, and I use the command line:

mingw32-make first

But instead of compiling my files, I only get the message:

cc  first.c -o first
process_begin: CreateProcess(NULL, cc first.c -o first, ...) failed
make (e=2): The system cannot find the file specified.
<builtin>: recipe for target 'first' failed
mingw32-make: ***[first] Error 2

I guess it's probably something really stupid, but I just can't figure out what I'm doing wrong. I really appreciate any help on this. Thank you so much in advance.

Upvotes: 2

Views: 2783

Answers (1)

Gibbon1
Gibbon1

Reputation: 31

So I went and tried it and... it works for me with MinGW-4.7.1 on a Win7 machine.... I'm wondering if make it picking up an environment variable or some such.

Try verifiying the version of make and gcc are what you expect

mingw32-make -v gcc -v mingw32-gcc -v

Also Try this makefile and see what happens.

CC = mingw32-gcc

second.o: second.c second.h
    $(CC)   -c   second.c
first.o:    first.c
    $(CC)   -c   first.c
first:   first.o  second.o
    $(CC) first.o second.o  -o first

Note convert spaces to tabs!

And compile via

mingw32-make SHELL=cmd.exe first

See what happens.

Upvotes: 1

Related Questions