开发者

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开发者_StackOverflow
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?


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 has shown how to get the Makefile to work. Here's how to make it simpler:

all: load list

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜