Reputation: 495
I've made a makefile to compile program calc.cpp
:
SRCS=calc.cpp
OBJS=$(subst .cpp,.o,$(SRCS))
FLGS=-std=c++17
all: calc clean
calc:
g++ $(SRCS) $(FLGS) -o $(OBJS)
./calc.o
clean:
rm -f $(OBJS)
However, I'm getting some strange errors:
make all
, it only prints rm -f calc.o
clean
section from all
, it prints make: Nothing to be done for 'all'.
make calc
, it prints make: 'calc' is up to date.
What is going on here, and why does make calc
not compile my code?
Upvotes: 2
Views: 458
Reputation: 100781
This rule:
calc:
...
tells make how a target calc
can be built and that it has no prerequisites. This means that if the file exists, make considers it up to date (how else, since it doesn't depend on anything)?
So presumably you have a file named calc
already existing in your directory, so when you run make calc
make thinks it's up to date.
You have to list some prerequisites of calc
if you want make to do something more than try to build the target if it doesn't exist.
Upvotes: 3