为什么出现错误“没有规则使目标'成为'"?当makefile是这样的时候? [英] Why the error "no rule to make target 'it'" when the makefile is like this?
问题描述
[root@localhost src]# cat Tmake
check=love
check+=it
all: $(check)
love:
echo "love"
loveit:
echo "loveit"
[root@localhost src]# make -f Tmake
echo "love"
love
make: *** No rule to make target `it', needed by `all'. Stop.
为什么找不到它?它不查找love
或loveit
,而是查找it
;我不明白.
Why can't it find it? It doesn't look for love
or loveit
but it
; I can't understand it.
推荐答案
宏check
以值love it
结尾; +=
操作会在空格后面添加新单词,而不管+=
运算符周围是否有空格.
The macro check
ends up with the value love it
; the +=
operation adds the new word after a blank, regardless of whether there are spaces around the +=
operator.
因此,all
规则取决于love
和it
.您已经告诉了它如何制作love
,但是没有告诉它如何制作it
(并且大概没有文件it.*
可以使用推理规则进行编译以创建it
),因此您会收到错误消息.
The all
rule therefore depends on love
and it
. You've told it how to make love
, but you've not told it how to make it
(and presumably you have no files it.*
that can be compiled to create it
using inference rules), so you get the error message.
您可以通过一条规则来证明这一点:
You could demonstrate this by having a rule:
check:
@echo $(check)
在all
规则之前.这将显示love
和it
之间的空间.
before the all
rule. This would show the space between love
and it
.
6.6在变量中添加更多文本
通常,将更多文本添加到已定义的变量的值中很有用.你做这个 包含
+=
的行,如下所示:
6.6 Appending More Text to Variables
Often it is useful to add more text to the value of a variable already defined. You do this with a line containing
+=
, like this:
objects += another.o
这将获取变量objects
的值,并向其添加文本another.o
(之前
一个空格).
This takes the value of the variable objects
, and adds the text another.o
to it (preceded
by a single space).
请注意,在POSIX规范中毫无意义,因为+=
是GNU make
中的扩展.
Note that there is no point in looking in the POSIX specification for this since +=
is an extension in GNU make
.
这篇关于为什么出现错误“没有规则使目标'成为'"?当makefile是这样的时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!