无限循环 [英] infinite loop in makefiile

查看:56
本文介绍了无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解了makefile文件中的递归变量.因为我们在以下代码中添加了"=",所以它是一个递归变量,与:="

I read about recursive variable in makefiles. Because we put '=' in the following code, it's a recursive variable, as apposed to ':='

CC = gcc -Wall
# we want to add something to the end of the variable
CC = $(CC) -g
hello.o: hello.c hello_api .h
$(CC) -c hello.c -o hello.o

我还是不明白,为什么在这种情况下我们会有一个无限循环.

I didn't understand still, why in this case we have an infinent loop.

推荐答案

来自手册:

变量的第一种方式是递归扩展变量. [...]您指定的值是逐字安装的;如果它包含对其他变量的引用,则每当替换此变量时(在扩展其他字符串的过程中),这些引用就会被扩展.发生这种情况时,它称为递归扩展.

The first flavor of variable is a recursively expanded variable. [...] The value you specify is installed verbatim; if it contains references to other variables, these references are expanded whenever this variable is substituted (in the course of expanding some other string). When this happens, it is called recursive expansion.

您的CC变量就是这种味道.它的内容从字面上是$(CC) -g;不是 gcc -Wall -g.因此,当您扩展此变量时,首先要扩展$(CC),它再次包含对自身的引用,因此具有无限递归.

Your CC variable is of this flavour. It's content is literally $(CC) -g; it is not gcc -Wall -g. So when you expand this variable, you first expand $(CC), which again contains the reference to itself, and so you have infinite recursion.

使用:=的区别在于立即评估右侧,并将结果分配给变量.

The difference when using := is that the right-hand-side is evaluated immediately and the result is assigned to the variable.

这篇关于无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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