views:

729

answers:

3

Hello, so I've been programming in C++ for almost 2 years now, and the whole while I've had the pleasure of using an IDE (VS) with lovely project settings and automatic linking and the like. I've always stayed away from any external libraries which required me to compile via makefiles, or at least the ones which were meant for linux environments/other compilers.

Anyways I now want to use a super handy utility (Bob Jenkins Perfect Minimal Hash) but it requires me to compile via makefiles, not only that but using the g++ compiler.

I went ahead and got the mingW32-make utility and am now trying to get it to work. Where I'm at now:

  • Succesfully installed minGW
  • Succesfully called the make utility
  • Failed to succesfully make the project.

The error I get is:

C:\gen_progs\ph>mingw32-make

mingw32-make: *** No rule to make target lookupa.c', needed by lookupa.o'. Stop.

And the makefile itself:

CFLAGS = -O

.cc.o:
    gcc $(CFLAGS) -c $<

O = lookupa.o recycle.o perfhex.o perfect.o

const64 : $(O)
    gcc -o perfect $(O) -lm

# DEPENDENCIES

lookupa.o : lookupa.c standard.h lookupa.h

recycle.o : recycle.c standard.h recycle.h

perfhex.o : perfhex.c standard.h lookupa.h recycle.h perfect.h

perfect.o : perfect.c standard.h lookupa.h recycle.h perfect.h

Now the error seems reasonable, at least from my minimal understanding of makefiles, I have all the referenced .c, .h files, however I have none of the .o files and there doesn't appear to be any instructions on how to make these. So my question/s are:

am I calling the make utility wrong? Or do I need to compile the object files first? Or... do I need to add something to the make file?

Again I have all the referenced .c and .h files.

Edit: Sorry about that I was actually missing that specific file it seems to have disapeared somewhere along the line. However, adding it back in this is the error I now get:

c:\gen_progs\ph>mingw32-make 
cc -O   -c -o lookupa.o lookupa.c 
process_begin: CreateProcess(NULL, cc -O -c -o lookupa.o lookupa.c, ...) failed.

make (e=2): The system cannot find the file specified. 
mingw32-make: *** [lookupa.o] Error 2
+1  A: 

I don't think not having .o files is the problem. Make will make them from the source files (the files to the right of the colon).

Your immediate problem seems to be that make can't file the file "lookupa.c". From the rules you posted, it looks to me like that file should be sitting in the same directory as the makefile, but it isn't. You need to figure out where that file is, and how to get it there.

(For some reason I have a mental image of Wile E. Coyote sitting at his computer, seeing that file name, looking up, and getting plastered with an anvil).

T.E.D.
Thanks, that fixed that error, now another one, and actually the original one. Somehow the .c file was deleted along my random attempts at making the project. Its back now.
DeusAduro
+3  A: 

Regarding your error "process_begin: CreateProcess(NULL, cc -O -c -o lookupa.o lookupa.c, ...) failed."

This is because the make utility wants to use the "cc" compiler to compile your program, but that compiler is not part of the Mingw-package.

Solution: Change the ".cc.o:" to ".c.o:". This changes the implicit rule which tells Make what compiler to use (gcc on the next line) when compiling .c files (the original line tells it how to compile .cc files).

Terje Mikal
Thank you very much, worked like a charm. Learn something every day!
DeusAduro
A: 

Saying either make -DCC=gcc at the command line or adding the line CC=gcc to the top of the Makefile would cure the issue as well. Make's built in rules for handling C source code all name the C compiler with the variable CC, which defaults to "cc" for reasons of backward compatibility even in Gnu Make.

It looks like the original Makefile author tried to work around that problem by supplying a custom rule for compiling .cc files, but since there are no .cc files in the project that rule was not actually used.

Specifying the correct value for CC is superior to fixing the explicit rule to name .c files IMHO because Makefiles are generally easier to use and maintain and are the most portable when the least possible information is specified.

RBerteig