簡體   English   中英

makefile 中的 Match-Anything 模式規則的行為

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM