[英]Behavior of Match-Anything Pattern Rules in makefile
假设我的来源是test.c
:
#include <stdio.h>
int main()
{
printf("%s\n", "hi");
}
我希望在名为bin
的文件夹中创建名为test
的可执行文件。 所以我的makefile
是:
all:bin/test
当我执行make
时,我希望发生以下内置规则:
%: %.c
# recipe to execute (built-in):
$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
因为目标%
应该匹配bin/test
并且由于test.c
存在,它应该执行配方。 但是, make
说: No rule to make target 'bin/test', needed by 'all'. Stop.
No rule to make target 'bin/test', needed by 'all'. Stop.
为什么会这样?
如果%
匹配bin/test
,那么先决条件是bin/test.c
,它不存在。 因此,Make 在搜索构建bin/test
的规则时拒绝该隐式规则。 它找不到其他符合要求的规则,并告诉你。
如果您尝试构建test
,或将test.c
移动到bin/
,那么 Make 将使用此规则。
如果您想从工作目录中的源代码在bin/
中构建二进制文件,您可以编写自己的模式规则,如下所示:
bin/%: %.c
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.