[英]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.