neuromancer
neuromancer

Reputation: 55579

How to fix this Makefile

I want my Makefile to be as simple as possible and still function. This is what it looks like.

load: load.cpp
    g++ load.cpp -g -o load
list: list.cpp
    g++ list.cpp -g -o list

It worked fine when there was only one entry. But when I added the second entry, it doesn't check to see if it's updated and needs to be recompiled, unless I specifically supply the name. How do I fix this?

Upvotes: 2

Views: 267

Answers (2)

Beta
Beta

Reputation: 99174

Dave Hinton has shown how to get the Makefile to work. Here's how to make it simpler:

all: load list

%: %.cpp
    g++ $< -g -o $@

Upvotes: 2

dave4420
dave4420

Reputation: 47062

Make only makes the first target automatically. So add a new first target that depends on both the others.

all: load list

load: load.cpp
    g++ load.cpp -g -o load

list: list.cpp
    g++ list.cpp -g -o list

Upvotes: 5

Related Questions