您的位置:首页 > 其它

Avoiding ``No rule to make target ...'' Errors

2010-09-16 11:19 537 查看
在GNU make手册4.14节 给出一种基本的自动生成依赖关系的rules

%.d: %.c
@set -e; rm -f $@; /
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; /
sed 's,/($*/)/.o[ :]*,/1.o $@ : ,g' < $@.$$$$ > $@; /
rm -f $@.$$$$

大部分情况下这个都是可以工作的,但是这个仍然有很多的局限,GNU Make的作者Paul Smith在自己的网站上对这个问题进行了详细的阐述,其中一个比较严重的问题

就是 当依赖的头文件由于不再使用被删除,此时在依赖性文件中依然存在对这个文件的依赖,当你make的时候,就会出现No rule to make target ...'' Errors

解决方法据我所知道的有两种


Paul在自己网站上的通过sed对这个依赖性文件在操作,使得每个prerequisites变成target,这样即使依赖的头文件被

删除了,也不会有问题,请参见http://mad-scientist.net/make/autodep.html#advanced 


使用 -MP 选项
from gcc manual
This option instructs CPP to add a phony target for each dependency other than the main file, causing each to depend on nothing. These dummy rules
work around errors make gives if you remove header files without updating the Makefile to match.
This is typical output:

test.o: test.c test.h
test.h:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐