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

  在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: 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值