【问题标题】:Why does my makefile variable not work when using the "define" directive?为什么我的 makefile 变量在使用“define”指令时不起作用?
【发布时间】:2018-12-15 17:41:53
【问题描述】:

我正在使用 GNU Make 3.81。以下 makefile 可以正常工作:

name=lucas

all: test

.PHONY: test
test: 
    echo $(name) # outputs variable correctly

但是当我尝试使用“define”指令定义变量时,它停止工作:

define name =
lucas
endef

all: test

.PHONY: test
test: 
    echo $(name)

为什么第二个版本不起作用?谢谢。

编辑:找到this related thread。好像是版本问题。 = 符号显然仅在 3.82 版之后才在定义语句中被识别。

【问题讨论】:

    标签: bash shell makefile gnu-make


    【解决方案1】:

    我很确定您的test 目标在echo $(name) 之前没有'\t'。 当我复制并粘贴您的 makefile 代码时,我看到了,但我认为不是 markdown 语言,因为我用 makefile 检查了其他问题,它在那里工作。

    【讨论】:

    • 我使用的是 GNU Make 3.81 版本。我想知道版本是否可能是我的问题。我完全不知所措,我无法让它工作。
    【解决方案2】:

    找到this related thread。好像是版本问题。在 3.82 之前的版本的定义语句中显然无法识别 = 符号。

    【讨论】:

    • 你的意思是,“define 3.82 之前的语句中无法识别 = 符号”,我猜。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2016-10-03
    相关资源
    最近更新 更多