jamesalone
jamesalone

Reputation: 341

Makefile is always not up to date even without any changes

I have a directory with two folders, src and bin with the makefile at root directory. This makefile keeps compiling (not up to date) even without changes. Am I missing something with this makefile?

all:
    make a b

a: ./src/a.cpp
    g++ -o ./bin/a ./src/a.cpp

b: ./src/b.cpp
    g++ -o ./bin/b ./src/b.cpp

Upvotes: 0

Views: 558

Answers (1)

melpomene
melpomene

Reputation: 85757

Your rules claim to create the files a and b, but they don't: They create bin/a and bin/b.

So when make checks your rules, it always finds that a and b don't exist and tries to create them by executing their associated commands.

Possible fix:

.PHONY: all

all: bin/a bin/b

bin/a: src/a.cpp
    g++ -o bin/a src/a.cpp

bin/b: src/b.cpp
    g++ -o bin/b src/b.cpp

On .PHONY: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets

Upvotes: 5

Related Questions