Makefile 中的 CC?= 是什么意思?

发布于 2024-09-04 10:18:38 字数 279 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

韬韬不绝 2024-09-11 10:18:38

来自 http://www.gnu.org/software/make/manual/make。 html

还有另一个赋值运算符
对于变量,“?=”。这被称为
条件变量赋值
运算符,因为它只有一个
如果变量还没有生效
定义的。本声明:

<前><代码> FOO ?= 条

与此完全等效(请参阅
原点函数):

 ifeq ($(原点 FOO), 未定义)
   FOO = 酒吧
 恩迪夫

可能 CC 已经定义为 gcc,因此 CC ?= g++ 不会覆盖现有的 gcc.

From http://www.gnu.org/software/make/manual/make.html:

There is another assignment operator
for variables, `?='. This is called a
conditional variable assignment
operator, because it only has an
effect if the variable is not yet
defined. This statement:

 FOO ?= bar

is exactly equivalent to this (see The
origin Function):

 ifeq ($(origin FOO), undefined)
   FOO = bar
 endif

Probably CC is already defined as gcc, so CC ?= g++ won't override the existing gcc.

最笨的告白 2024-09-11 10:18:38

?= 运算符仅在尚未设置变量时设置该变量:info make* 使用变量* 设置< /代码>。

The ?= operator sets the variable only if it isn't already set: info make* Using Variables* Setting.

心碎无痕… 2024-09-11 10:18:38

正如其他人提到的,它可能已经是预定义的。

在 GNU 上,您可以从不包含 Makefile 的目录中查看使用 make -p 定义的内容。

这记录在: https://www.gnu.org /software/make/manual/html_node/Implicit-Variables.html

抄送

用于编译C程序的程序;默认“抄送”。

通常,默认情况下为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 a Makefile.

This is documented at: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html

CC

Program for compiling C programs; default ‘cc’.

Usually, CC=cc by default. Then on Ubuntu 14.04 for e.g., cc is usually a symlink to gcc.

To disable all variables at once see: Disable make builtin rules and variables from inside the make file Seems currently impossible.

你曾走过我的故事 2024-09-11 10:18:38

这 ”?”运算符表示如果尚未设置则已设置。

因此,如果 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文