为什么出现错误“没有规则使目标'成为'"?当makefile是这样的时候? [英] Why the error "no rule to make target 'it'" when the makefile is like this?

查看:68
本文介绍了为什么出现错误“没有规则使目标'成为'"?当makefile是这样的时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[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.

为什么找不到它?它不查找loveloveit,而是查找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规则取决于loveit.您已经告诉了它如何制作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规则之前.这将显示loveit之间的空间.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆