GNU使产量“命令在第一个目标之前开始".错误 [英] GNU make yields "commands commence before first target" error
问题描述
在我的makefile文件中,我想检查是否存在库并给出提示性错误消息.我创建了一个条件,当找不到文件时,该条件应退出制作过程:
In my makefile, I would like to check for the existence of a library and give an informative error message. I created a conditional that should exit the make process when the file is not found:
9: ifeq ($(${JSONLIBPATH}),)
10: JSONLIBPATH = ${ALTJSONLIBDIR}/${LIBJSON}
11: endif
12: ifeq ($(${JSONLIBPATH}),)
13: $(error JSON library is not found. Please install libjson before building)
14: endif
我的makefile卡在第13行:
My makefile gets stuck on line 13:
Makefile:13: *** commands commence before first target. Stop.
第13行之后,我的makefile有其目标.
After line 13, my makefile has its targets.
我尝试将此条件块放入目标(例如称为isJSONLibraryInstalled
的目标)中,但这无法正确执行.
I tried putting this conditional block into a target (e.g. a target called isJSONLibraryInstalled
) but this does not execute correctly.
在处理目标之前,我将如何检查文件的存在并处理错误情况?抱歉,这是一个愚蠢的问题.
How would I check for a file's existence and handle the error case, before processing targets? Apologies if this is a dumb question.
推荐答案
首先,您正在查看以当前路径命名的变量的内容,这可能不是您想要的.一个简单的环境变量引用是$(name)
或${name}
,而不是$(${name})
.因此,始终会评估第13行.
First of all, you are looking at the contents of a variable that is named after the current path, which is probably not what you want. A simple environment variable reference is $(name)
or ${name}
, not $(${name})
. Due to this, line 13 is always evaluated.
第二,我认为这使$(error ...)
表达式的缩进令人窒息.当表达式解析为空字符串时,该行的开头仍然有一个制表符,它表示命令,而该命令又不能存在于规则之外.
Second, I think it is choking on the indentation of the $(error ...)
expression. While the expression resolves to an empty string, there is still a tab character at the start of the line, which indicates a command, which in turn cannot exist outside a rule.
我认为使用空格而不是制表符来缩进是可行的.
I think using spaces rather than tabs to indent would work.
这篇关于GNU使产量“命令在第一个目标之前开始".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!