最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Makefile执行过程中出错:make: *** No rule to make target ` ‘, needed by xxx. Stop.

makefile crifan 59716浏览 0评论

【问题】

有个已有的Makefile,执行过程中出错:

CLi@PC-CLI-1 ~/develop/docbook/books/python_topic_str_encoding/src
$ make html
=============================== cleaning html ==============================
rm -rf ../output/html/single/*
make: *** No rule to make target ` ‘, needed by `../output/html/single/python_topic_str_encoding.html’.  Stop.

 

【解决过程】

1.换到别的,和当前文件夹等价的路径中去执行,结果却是正常的:

CLi@PC-CLI-1 ~/develop/docbook/books/python_topic_str_encoding/src
$ cd ../../python_topic_web_scrape/src

CLi@PC-CLI-1 ~/develop/docbook/books/python_topic_web_scrape/src
$ make html
=============================== cleaning html ==============================
rm -rf ../output/html/single/*
=============================== generating html ==============================
export XML_CATALOG_FILES="/home/develop/docbook/config_root/catalog/catalog.xml" && \
export XML_DEBUG_CATALOG=1 && \

……

 

2.后来折腾半天,最后终于发现,原来是由于,当前Makefile中的内容是:

# also means main source file name
PROJECT_NAME = python_topic_str_encoding
SUB_SRC_FILES = \
    python_topic_str_encoding.xml \
    preface.xml \
    ch01_2x_vs_3x.xml \
    ch02_common_encoding_error.xml \
    ch03_other_common_case.xml \
    reference.xml \    

DOCBOOK_MAKEFILE_ROOT = ../../../config
################################################################################
# Include docbook makefile
################################################################################
include $(DOCBOOK_MAKEFILE_ROOT)/docbook.mk

其中,注意到,所依赖的

reference.xml \

后面还有几个空格的,截图才能看出来:

xml follow with space

导致了此错误。

把最后的,多余的空格去掉:

removed unuseful space

就可以消除此问题了。

 

【总结】

Makefile在编译执行过程中,对于所依赖的条件,此处即一堆xml文件,最后一个是reference.xml,结果由于最后reference.xml后面,有多余的4个空格,导致Makefile将该处的4个空格,视为一个文件了,所以,必然找不到该“文件”,所以才报错的。

所以,如果Makefile出现:

make: *** No rule to make target ` ‘, needed by xxx. Stop.

的错误,那么基本上都是属于找不到所依赖的文件所导致的,所以应该去:

检测确保,所依赖的文件,是否真实存在。

很可能,很常见的一个现象就是,此处的,误写了多余的空格,导致被视为依赖文件,导致找不到,导致报此错误。

解决办法就很简单,去掉多余的空格即可。

转载请注明:在路上 » 【已解决】Makefile执行过程中出错:make: *** No rule to make target ` ‘, needed by xxx. Stop.

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (2)

  1. 也碰到这个问题,之前编译是没有问题的,再次编译就报了这个错,试了楼主的这个方法,还是会报一样的错。后来删除了报错的.o文件,再次编译就ok了。
    faith8年前 (2016-09-29)回复
  2. 刚碰到了,这问题太不容易发现了。
    xhhjin8年前 (2015-11-19)回复
86 queries in 0.174 seconds, using 22.21MB memory