【问题标题】:How to setup a target in Makefile to call 2 targets如何在 Makefile 中设置目标以调用 2 个目标
【发布时间】:2020-08-22 07:54:19
【问题描述】:

我尝试在 MakeFile 中设置一个目标来调用同一个 Makefile 中的 2 个目标。

build: copy
    copy2

copy:
    cp dir/* ${DIR}

copy2:
    cp dir2/* ${DIR}

但是当我在 shell 中运行make 时,我看到它只执行第一个目标并且它说

make: copy2: No such file or directory make: *** [build] Error 1

我基本上把copy2改成和copy一样来调试。但我不明白为什么 Make 找不到第二个目标“copy2”?

你能告诉我我错过了什么吗?

【问题讨论】:

    标签: makefile


    【解决方案1】:

    第 2 行的 copy2 是 make 将尝试执行的命令。大概该命令在您的系统上不存在,因此 make 会抛出错误“copy2” - command not found。

    改为这样做:

    build: target1 target2:
        echo Both targets have been run!
    
    target1:
        echo Running target 1
    
    target2:
        echo Running target 2
    

    输出:

    echo Running target 1
    Running target 1
    echo Running target 2
    Running target 2
    echo Both target2 have been run!
    Both target2 have been run!
    

    【讨论】:

      猜你喜欢
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-02
      • 2023-03-30
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多