Alright so this is my current setup for a makefile. There are files which are named public01.c, public02.c, etc. I’m trying to make object files for each of them using the public*.o label with a wildcard.
public*.o: public*.c hashtable.h
$(CC) $(CFLAGS) -c public*.c
public*: public*.o
$(CC) -o public* public*.o
However, when I try and run the makefile, I get this:
make: *** No rule to make target `public*.c', needed by `public*.o'. Stop.
I guess it’s treating public*.c as a label and not a wildcard as I’d like. I read about $(wildcard pattern...) function and played around with it, but I didn’t really understand it or got it to work…
Short answer: that syntax does not work the way you want it to. The correct way to do what you want in GNU make syntax is to use pattern rules:
Long answer: This:
does not mean what you want it to mean. Assuming you have several file
public01.c, etc., and no filespublic01.o, etc., at the start of your build, that syntax is equivalent to this:That is, if
public01.o, etc., do not exist, then make will use the literal stringpublic*.oas the filename. If some of the.ofiles do exist, then that syntax is equivalent to this:Seems like what you want right? But that’s a common misunderstanding with make, because in fact that line is exactly the same as this:
That is — every
.ofile has a dependency on every.cfile! The correct way to do what you want is to use a pattern rule, as shown above.