主题:[讨论]多目录,多目标的makefile问题
先看代码:
1. app : create_directories $(BDIR)$(LIB_PREFIX)app$(LIB_SUFFIX)
2. $(BDIR)$(LIB_PREFIX)app$(LIB_SUFFIX) : build_trace test.lib $(STAPP_OBJECTS)
3. @$(BUILD_APP_LIBRARY)
复制代码
其中:$(BUILD_APP_LIBRARY)是这样定义的
1. ifeq "$(ARCHITECTURE)" "ST40"
2. define BUILD_STAPP_LIBRARY
3. $(if $(wildcard $@),@$(RM) $@)
4. $(if $(wildcard ar.mac),@$(RM) ar.mac)
5. $(if $(filter %.o,$^),@$(AR) 2>$(NULL) -q $@ $(filter %.o,$^))
6. $(if $(filter %.a,$^),@echo OPEN $@ > ar.mac
7. $(foreach LIB,$(filter %.a,$^),
8. @echo ADDLIB $(LIB) >> ar.mac
9. )
10. @echo SAVE >> ar.mac
11. @echo END >> ar.mac
12. @$(AR) 2>$(NULL) -M <ar.mac
13. @$(RM) ar.mac
14. )
15. @$(AR) 2>$(NULL) -s $@
16. endef
17. endif
复制代码
整个编译没有问题,但是最后链接的时候,在APP中要用到test中的函数,却总是提示undefined reference to,
test.lib是另一个目标:
1. test.lib :
2. @$(MAKE) -C test
复制代码
1. app : create_directories $(BDIR)$(LIB_PREFIX)app$(LIB_SUFFIX)
2. $(BDIR)$(LIB_PREFIX)app$(LIB_SUFFIX) : build_trace test.lib $(STAPP_OBJECTS)
3. @$(BUILD_APP_LIBRARY)
复制代码
其中:$(BUILD_APP_LIBRARY)是这样定义的
1. ifeq "$(ARCHITECTURE)" "ST40"
2. define BUILD_STAPP_LIBRARY
3. $(if $(wildcard $@),@$(RM) $@)
4. $(if $(wildcard ar.mac),@$(RM) ar.mac)
5. $(if $(filter %.o,$^),@$(AR) 2>$(NULL) -q $@ $(filter %.o,$^))
6. $(if $(filter %.a,$^),@echo OPEN $@ > ar.mac
7. $(foreach LIB,$(filter %.a,$^),
8. @echo ADDLIB $(LIB) >> ar.mac
9. )
10. @echo SAVE >> ar.mac
11. @echo END >> ar.mac
12. @$(AR) 2>$(NULL) -M <ar.mac
13. @$(RM) ar.mac
14. )
15. @$(AR) 2>$(NULL) -s $@
16. endef
17. endif
复制代码
整个编译没有问题,但是最后链接的时候,在APP中要用到test中的函数,却总是提示undefined reference to,
test.lib是另一个目标:
1. test.lib :
2. @$(MAKE) -C test
复制代码