我有以下生成文件:力的makefile构建来源两次
all: a.out b.out
.PHONY: gen_hdr1
gen_hdr1:
#call script 1 that generates x.h
rm a.o #try to force rebuild of a.cpp
.PHONY: gen_hdr2
gen_hdr2:
#call script 2 that generates x.h
rm a.o #try to force rebuild of a.cpp
b.out: gen_hdr2 a.o
g++ -o b.out a.o
a.out: gen_hdr1 a.o
g++ -o a.out a.o
*.o : *.cpp
g++ -c $< -o [email protected]
a.cpp includex XH
我想要做什么:
- 是否存在
- 删除AO为应用A生成xh
- 编译a.cpp
- 构建应用甲
- 如果存在
- 生成XH为App乙
- 编译a.cpp再次
- 构建应用B
运行生成文件的输出被除去AO:
#call script 1 that generates x.h
rm -f a.o #try to force rebuild of a.cpp
g++ -c -o a.o a.cpp
g++ -o a.out a.o
#call script 2 that generates x.h
rm -f a.o #try to force rebuild of a.cpp
g++ -o b.out a.o
g++: a.o: No such file or directory
g++: no input files
make: *** [b.out] Error 1
基本上,应用程序B构建时找不到ao。 如何强制make系统重建它?
你有没有尝试过让'a.o'目标虚假?即'.PHONY:a.o' – 2012-04-18 07:36:16
是的,我将***。o:* .cpp **的一般规则替换为**。PHONY:a.o a.o:a.cpp **;这是你的意思? – 2012-04-18 07:57:52