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: 

你可能感兴趣的:(header,gcc,File,each,makefile,output)