【问题标题】:Explanation on how this makefile works?解释这个makefile是如何工作的?
【发布时间】:2013-11-13 04:30:44
【问题描述】:

我在阅读 Auto-Tools 时发现了一个 makefile here。

我从未使用过这样的 makefile,我自己尝试过。
我写的makefile的内容是:

all: HelloWorld

clean:
    rm -f HelloWorld *.o

包含 makefile 的文件夹仅包含一个文件 HelloWorld.c。

运行make 成功,输出如下:

$> make
cc     HelloWorld.c   -o HelloWorld

现在我尝试进行实验,并在生成文件中将all 的目标重命名为HelloWorl。这次make 失败并出现以下错误:

$> make
make: *** No rule to make target `HelloWorl', needed by `all'.  Stop.

请解释make自动搜索和编译源的这种行为。

我的理解是,它通过附加 .c 从目标名称中生成源名称,并使用默认的 cc 编译器对其进行编译。

【问题讨论】:

    标签: c makefile autotools


    【解决方案1】:

    您的理解大部分是正确的;这是implicit rules 之一。但是,make 实际上是使用 make 的 CC variable 中的编译器编译文件。

    【讨论】:

      猜你喜欢
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      • 2014-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多