【问题标题】:An Implicit rule without Prerequisites in MakefileMakefile 中没有先决条件的隐式规则
【发布时间】:2020-06-30 16:18:16
【问题描述】:

目录结构:

src
├── Makefile
├── grpc
│   ├── grpc_demo5_client.go
└── └── grpc_demo5_server.go

生成文件:

groc/test: groc/grpc_demo5_client.go

groc/%:
    echo $@ " - " $^

输出结果:

echo groc/grpc_demo5_client.go " - " 
groc/grpc_demo5_client.go  - 
echo groc/test " - " groc/grpc_demo5_client.go
groc/test  -  groc/grpc_demo5_client.go

documentation

隐式规则可以应用于与其模式匹配的任何目标, 但它仅适用于目标没有另外指定配方时, 并且只有在可以找到先决条件时。

我认为文件groc/grpc_demo5_client.go 不是目标。
我的问题是为什么echo groc/grpc_demo5_client.go " - " groc/grpc_demo5_client.go - 出现在输出结果中?

【问题讨论】:

    标签: makefile


    【解决方案1】:

    更多 documentation 来自与您的文档相同的来源:

    When a target is a file, it needs to be recompiled or relinked if any of its
    prerequisites change. In addition, any prerequisites that are themselves automatically
    generated should be updated first.
    

    由于groc/test 依赖于groc/grpc_demo5_client.gogroc/grpc_demo5_client.go 成为必须自己生成的目标。如果没有这种递归行为,make 几乎不会有用。

    still more documentation 中,它说:

    If none of the explicit rules for a target has a recipe, then make searches for
    an applicable implicit rule to find one 
    

    您的第一条规则没有配方,因此第二条规则中的配方用于groc/grpc_demo5_client.go

    但也许你的问题是你的 Makefile 中有拼写错误,groc 应该是grpc。试试:

    grpc/test: grpc/grpc_demo5_client.go
    
    grpc/%:
        echo $@ " - " $^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-13
      • 2015-05-18
      • 1970-01-01
      • 2013-03-11
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多