【发布时间】:2015-01-15 15:31:52
【问题描述】:
我有一个 drectiry subdir-test,其中包含子目录 obj bin src。我在 src 中有 3 个 makefile,在 obj 中有一个在 obj 中,在 sub-test 中有一个。 我想在其中使用递归 make,但出现错误。 目录结构是:
subdir-test
- Makefile1
- src
- all.c files and Makefile2
- obj
- all.o files and Makefile3
- include
- functions.h
- bin
以下是制作文件: Makefile1:
SUBDIRS = src obj
subdirs :
for dir in $(SUBDIRS);\
do \
$(MAKE) -C $$dir ;\
done
.PHONY : clean
clean :
rm -rf bin/* obj/*
Makefile2:
inc = -I ../include/
all : main.o factorial.o
main.o : main.cpp functions.h
cc -c $< -I $(inc) -o ../obj/$@ -lstdc++
factorial.o : factorial.cpp functions.h
cc -c $< -I $(inc) -o ../obj/$@ -lstdc++
Makefile3:
run : main.o factorial.o
cc $^ -o ../bin/$@
从子测试目录调用 make -f Makefile1 时出现以下错误:
for dir in src obj;\
do \
make -C $dir ;\
done
make[1]: Entering directory `/home/betatest/Public/subdir-test/src'
make[1]: *** No rule to make target `functions.h', needed by `main.o'. Stop.
make[1]: Leaving directory `/home/betatest/Public/subdir-test/src'
make[1]: Entering directory `/home/betatest/Public/subdir-test/obj'
make[1]: *** No rule to make target `main.o', needed by `run'. Stop.
make[1]: Leaving directory `/home/betatest/Public/subdir-test/obj'
make: *** [subdirs] Error 2
还有一个问题,我想写for循环如下:
for dir in $(SUBDIRS)
do
$(MAKE) -C $$dir
done
我在 for 循环中也遇到了错误。我哪里错了。
【问题讨论】:
-
如果您的 make 文件未命名为
makefile或Makefile(或者可能是其他混合大小写的变体,取决于您的make版本),那么您还必须告诉make哪个要使用的文件 - 比如make -C src -f Makefile2... -
不是那个问题,但问题是头文件在包含文件夹中,它没有被包含在 src 文件夹 Makefile2 中,所以我认为我在“inc”变量使用方面是错误的。请提出解决方案如何包含包含文件夹中的头文件。