tags:

views:

43

answers:

2

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?

+5  A: 

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
Dave Hinton
+2  A: 

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 $@
Beta