Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Small Gcc Project on Windows Using MinGW

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
like image 562
DeusAduro Avatar asked Aug 06 '09 17:08

DeusAduro


2 Answers

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).

like image 118
Terje Mikal Avatar answered Oct 02 '22 04:10

Terje Mikal


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.

like image 33
RBerteig Avatar answered Oct 02 '22 05:10

RBerteig