【问题标题】:Make - Nothing to be done for - only with file extensionMake - 无事可做 - 仅使用文件扩展名
【发布时间】:2013-06-07 17:03:54
【问题描述】:

我有一个简单的 c 程序 - hello_world.c

从文件名可以看出我对 c 非常陌生。

我希望执行以下编译:

make hello_world.c

但这会给出错误消息:make: Nothing to be done for hello_world.c.

如果我只是做make hello_world 它可以工作,即没有扩展名。

谁能解释这是为什么?

【问题讨论】:

    标签: c compilation makefile


    【解决方案1】:

    make 将目标作为其参数。如果你告诉它你想要创建hello_word.c,它会查看,发现该文件已经存在并且没有依赖关系,并会决定它是最新的 - 因此无事可做。

    当你说make hello_world,make 寻找hello_word,找不到它,然后寻找hello_world.o,找不到它,然后寻找hello_world.c,找到它,然后使用它从中构建hello_world 的隐式规则。

    您可以使用make -d 查看make 在此过程中所做的决定。这是make hello_world.c 的示例 - 我已经剪掉了一堆来展示最后一部分,这是你关心的:

    ...
    Considering target file `hello_world.c'.
     Looking for an implicit rule for `hello_world.c'.
     ...
     No implicit rule found for `hello_world.c'.
     Finished prerequisites of target file `hello_world.c'.
    No need to remake target `hello_world.c'.
    make: Nothing to be done for `hello_world.c'.
    

    那么,对于make hello_world

    ...
    Considering target file `hello_world'.
     File `hello_world' does not exist.
     Looking for an implicit rule for `hello_world'.
     Trying pattern rule with stem `hello_world'.
     Trying implicit prerequisite `hello_world.o'.
     Trying pattern rule with stem `hello_world'.
     Trying implicit prerequisite `hello_world.c'.
     Found an implicit rule for `hello_world'.
      Considering target file `hello_world.c'.
       Looking for an implicit rule for `hello_world.c'.
       Trying pattern rule with stem `hello_world'.
       ...
       No implicit rule found for `hello_world.c'.
       Finished prerequisites of target file `hello_world.c'.
      No need to remake target `hello_world.c'.
     Finished prerequisites of target file `hello_world'.
    Must remake target `hello_world'.
    cc     hello_world.c   -o hello_world
    ...
    Successfully remade target file `hello_world'.
    

    【讨论】:

    • 哦,所以当我调用 make 时,它​​正在查看当前目录中的文件
    【解决方案2】:

    “Make”是一种用于构建具有多个源文件的重要项目的工具。如果您只想编译单个 C 文件,请使用 C 编译器。 cc 通常可用作 C 编译器的命令行名称,尽管 gcc 也是一个通用名称(可能指同一个编译器)。

    【讨论】:

    • make 即使对于单文件项目也非常方便。例如,隐式规则允许您通过环境变量轻松一致地传递编译器标志。
    • 我们可能不得不同意不同意。我承认在这一点上我几乎不是make 的粉丝。
    猜你喜欢
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    相关资源
    最近更新 更多