rjc810
rjc810

Reputation: 495

makefile for c++ compilation not running

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:

What is going on here, and why does make calc not compile my code?

Upvotes: 2

Views: 458

Answers (1)

MadScientist
MadScientist

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

Related Questions