GNU make 产生“命令在第一个目标之前开始”错误
在我的 makefile 中,我想检查库是否存在并给出信息丰富的错误消息。我创建了一个条件,当找不到文件时应该退出 make 进程:
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
My makefile 卡在第 13 行:
Makefile:13: *** commands commence before first target. Stop.
在第 13 行之后,我的 makefile 有了它的目标。
我尝试将此条件块放入目标中(例如,名为 isJSONLibraryInstalled
的目标),但这无法正确执行。
在处理目标之前,如何检查文件是否存在并处理错误情况?如果这是一个愚蠢的问题,我深表歉意。
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
My makefile gets stuck on line 13:
Makefile:13: *** commands commence before first target. Stop.
After line 13, my makefile has its targets.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,您正在查看以当前路径命名的变量的内容,这可能不是您想要的。简单的环境变量引用是
$(name)
或${name}
,而不是$(${name})
。因此,始终会评估第 13 行。其次,我认为它因
$(error ...)
表达式的缩进而令人窒息。虽然表达式解析为空字符串,但行的开头仍然有一个制表符,它表示命令,而命令又不能存在于规则之外。我认为使用空格而不是制表符来缩进会有效。
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.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.
当您收到 Make 错误消息时,请务必检查错误消息文档
在 GNU Make 3.81 上(
error
似乎已从较新版本中删除),它显示:使事情更加混乱的是“似乎不是合法的 make 命令”部分。这解释了为什么 in:
错误发生在第 2 行而不是第 1 行:
make
只是接受它可以解析的语句,例如赋值,因此以下内容有效:注意:SO 目前在代码中将制表符转换为空格,因此您不能仅将上述代码复制到编辑器中。
When you get Make error messages, always check the Error message documentation
On GNU Make 3.81 (
error
appears to have been removed from newer versions), it says:What makes matters more confusing is that "doesn't appear to be a legal make command" part. That explains why in:
the error happens at line 2 and not 1:
make
simply accepts statements that it can parse, like the assignment, so the following works:Note: SO currently converts tabs to spaces in code, so you can't just copy the above code into your editor.
对我来说,造成这种情况的连接器之前有一个不必要的空白。
在 slickEdit 上,我选择了查看所有特殊字符的选项,并注意到了害群之马。
For me it was an unnecessary white space before the connector that was causing this.
On slickEdit I selected the option to view all special character and noticed the black sheep.
您可以使用VSCode检查空白、空格和制表符 [查看>渲染空白]
如您所见;
所以,您应该删除末尾的空格,并使用相同的操作应用相同的空格。例如:选项卡如下所示;
You can check whitespaces, spaces and tabs by using VSCode [View > Render Whitespace]
As you can see;
So, you should remove the whitespaces at the end and apply the same spaces with the same action. e.g: tab like the following;