+ TT_Project1

问题描述 投票:0回答:1

makefile + TT_Project2

+ makefile
|
+ TT_Project1
|      obj/
|      makefile
+ TT_Project2
|      obj/
|      makefile
+ TT_Project3
|      obj/
|      makefile

makefile + TT_Project3 /obj

makefile The top level makefile ....oFirst, this is wrong:

TT := libTT.a

SUBDIRS := $(wildcard */.)
OBJECTS := $(wildcard $(addsuffix *.o,$(SUBDIRS)/obj))

all: $(TT) $(OBJECTS)

$(TT) : $(OBJECTS)
    ar rcs $(TT) $(OBJECTS)

$(SUBDIRS):
    $(MAKE) -C $@

Not only are you missing a *.o between the /obj and .o, but you need to put the

in the first argument to
makefile
1个回答
1
投票

. Then the

OBJECTS := $(wildcard $(addsuffix *.o,$(SUBDIRS)/obj))

will expand to:/which gives:objwhich is clearly wrong. You want this:*.oHowever, that /objisn'taddsuffix what you want. It won't work because these variables are expanded when the makefile is read, before any actions have been taken. Before the makefile actually builds anything, there will be no SUBDIRS files existing, which means the foo/. bar/. baz/. function will match nothing.addsuffixIn your case that's a good thing, because if it

$(addsuffix *.o,foo/. bar/. baz/./obj)

did

foo/.*o bar/.*.o baz/./obj*.o

match anything you'll get errors because make doesn't know how to build those objects: they're built by the sub-makes.

OBJECTS := $(wildcard $(addsuffix /obj/*.o,$(SUBDIRS)))

But, since you have nothing that depends on the target they won't get built anyway: those recipes will never run.The easiest thing you can do is something like this:.oThe downside of this is that it will rebuild the library every time you run wildcard even if no objects have been changed. To fix that you'll have to add some complexity.

在顶层创建一个静态库。由于我的输出库太小,所以失败了...。我可以清楚地看到,它正在运行它下面的makefiles,而且它们是把 在其

果然如我所料。但我未能抓住所有的 SUBDIRS 我想... ...任何帮助都是感激的。

TT := libTT.a

SUBDIRS := $(wildcard */.)

all: $(TT)

$(TT) : $(SUBDIRS)
        ar rcs $(TT) $(addsuffix /obj/*.o,$(SUBDIRS))

$(SUBDIRS):
        $(MAKE) -C $@
.PHONY: $(SUBDIRS)

make我有以下层次结构。+ makefile

© www.soinside.com 2019 - 2024. All rights reserved.