Makefile 中的 CC?= 是什么意思?
我有一个 C 程序的 Makefile,其声明为“
CC?=gcc
将其更改为
CC?=g++
不会使其使用 g++ 进行编译”。将其更改为
CC=g++
确实会使其使用 g++。
所以我想知道 ?= 运算符的作用是什么?我的猜测是它会查看环境变量来决定使用哪个编译器,如果未设置则使用 gcc?任何人都可以解决这个问题吗?
I have a Makefile for a C program that has the declaration
CC?=gcc
Changing it to
CC?=g++
does NOT make it compile with g++. Changing it to
CC=g++
DOES make it use g++.
So I wonder what the ?= operator does? My guess is that it looks at a environment variable to decide which compiler to use and if it's not set then use gcc? Anyone who can clear this up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 http://www.gnu.org/software/make/manual/make。 html:
可能
CC
已经定义为gcc
,因此CC ?= g++
不会覆盖现有的gcc.
From http://www.gnu.org/software/make/manual/make.html:
Probably
CC
is already defined asgcc
, soCC ?= g++
won't override the existinggcc
.?=
运算符仅在尚未设置变量时设置该变量:info make
→* 使用变量
→* 设置< /代码>。
The
?=
operator sets the variable only if it isn't already set:info make
→* Using Variables
→* Setting
.正如其他人提到的,它可能已经是预定义的。
在 GNU 上,您可以从不包含
Makefile
的目录中查看使用make -p
定义的内容。这记录在: https://www.gnu.org /software/make/manual/html_node/Implicit-Variables.html
通常,默认情况下为
CC=cc
。例如,在 Ubuntu 14.04 上,cc
通常是gcc
的符号链接。要立即禁用所有变量,请参阅: 禁用 make来自 make 文件内部的内置规则和变量 目前看来是不可能的。
As others mentioned, it is likely already predefined.
On GNU, you can see what is defined with
make -p
from a directory that does not contain aMakefile
.This is documented at: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
Usually,
CC=cc
by default. Then on Ubuntu 14.04 for e.g.,cc
is usually a symlink togcc
.To disable all variables at once see: Disable make builtin rules and variables from inside the make file Seems currently impossible.
这 ”?”运算符表示如果尚未设置则已设置。
因此,如果 CC 已经为空,则 CC?= 将设置它。如果 CC 已经包含某些内容,则不会。
资料来源: http://unix.derkeiler.com/邮件列表/FreeBSD/questions/2007-03/msg02057.html
The "?" operator means set if not already set.
So, if CC is already blank CC?= will set it. If CC already contains something, it won't.
Source: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2007-03/msg02057.html