[英]What is the difference between := and += in make file?
以下陈述中的工作区别是什么?
LDDIRS := -L$(ORACLE_LIB)
LDDIRS += -L$(ORACLE_LIB)
:=(简单扩展变量)扫描值一次,全部展开任何值
定义变量时引用其他变量和函数。 例如x:=foo
y:=$(x) bar
x:=later
所以上面相当于
y:=foo bar
x:=later
+ =用于向变量附加更多文本,例如
objects=main.o foo.o bar.o
objects+=new.o
将对象设置为'main.o foo.o bar.o new.o'
=是递归扩展变量。值是逐字安装; 如果它包含对其他变量的引用,则只要替换此变量,就会扩展这些变量。这称为递归扩展。
“=”用于定义递归扩展变量。 以下make文件将打印出“y is later bar”
x = foo
y = $(x) bar
x = later
all:;echo "y is" $(y)
“:=”用于定义简单扩展变量,它一劳永逸地扩展。 以下make文件将打印出“y is foo bar”
x := foo
y := $(x) bar
x := later
all:;echo "y is" $(y)
此外,正如其他人之前指出的那样,您可以在GNU make手册的“ 使用变量”部分中获得更多详细信息。
希望这可以帮助 :-)
:=
此处定义变量是左手侧, +=
添加的右手侧到该变量的现有值。 比较:=
with =
评估使用地点的右侧(而不是在此特定行)
您可以在这里查看手册(假设您使用的是GNU make)
GNU Make has three assignment operators, ":=" , "=", "?=" and one "+=" for appending
to the varibles.
- ":=" performs immediate evaluation of the right-hand side and stores an actual
string into the left-hand side.
eg:
x:=foo
y:=$(x) bar
x:=later
so above is equivalent to
y:=foo bar
x:=later
test above example
x := foo
y := $(x) bar
x := later
all:;echo "y is" $(y)
output
------
y is foo bar
- "=" is like a formula definition; it stores the right-hand side in an
unevaluated form and then evaluates this form each time the left-hand
side is used.
eg:
x = foo
y = $(x) bar
x = later
all:;echo "y is" $(y)
output
------
y is later foo
“?=”仅在未设置/没有值时分配。 例如:KDIR?=“foo”KDIR?=“bar”测试:echo $(KDIR)会打印“foo”
“+ =”用于向变量追加更多文本。 例如,objects = main.o foo.o bar.o objects + = new.o
将对象设置为'main.o foo.o bar.o new.o'
:=
会将值设置为变量一次,即每次都不会重新评估变量。 编译代码时可以在性能上产生巨大的差异。
+=
将简单地将值加到变量上。
:=
用于分配,方式与=
相同。
+=
为变量添加新值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.