【发布时间】:2012-04-18 15:50:51
【问题描述】:
我有以下生成文件:
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 $@
a.cpp includex x.h
我想做什么:
- 如果存在则删除 a.o
- 为应用 A 生成 x.h
- 编译a.cpp
- 构建应用 A
- 如果存在则删除 a.o
- 为应用 B 生成 x.h
- 再次编译a.cpp
- 构建应用 B
运行makefile的输出是:
#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
基本上,在构建 App B 时找不到 a.o。 如何强制 make 系统重建它?
【问题讨论】:
-
您是否尝试过伪造
a.o目标? IE。.PHONY: a.o -
是的,我将 *.o : *.cpp 的一般规则替换为 .PHONY: a.o a.o : a.cpp ;这就是你的意思?