【问题标题】:Makefile not rebuilding dependenciesMakefile 不重建依赖项
【发布时间】:2012-10-04 18:29:33
【问题描述】:

我不熟悉使用 makefile 并尝试生成基本的 makefile 作为大学练习的一部分。我有两个源代码文件,chello.c 和 writeexit.s,它们必须经过编译/汇编,然后链接以生成 chello。

这是我目前的 makefile 代码:

chello: chello.o  writeexit.o
  ld -N chello.o writeexit.o -o chello

chello.o: chello.c
  gcc -c chello.c -o chello.o

writeexit.o: writeexit.s
  as writeexit.s -o writeexit.o

ld、gcc 和 as 之前的空格都是制表符,所以我认为空格很好。当我调用“make makefile”时,它返回“make: Nothing to be done for `makefile”。但是,如果我更改了 chello 的依赖项,例如 chello.c,则会返回相同的消息,并且不会修改 chello 的行为。

【问题讨论】:

  • 你如何调用make?听起来您可能正在输入make makefile,而您应该输入make -f makefile 或(除非您还有一个名为Makefile 的文件潜伏在同一目录中),只是make

标签: makefile


【解决方案1】:

这里的替代帐户,如果我只调用“make”而不是“make makefile”,它似乎工作正常。这个问题可以忽略。

【讨论】:

  • 只是补充一点,如果在调用 make 时没有指定目标,它将构建文件中列出的第一个目标。因此,大多数 Makefile 都会将“all”作为列出的第一个目标。
【解决方案2】:

来自man make

make 执行 makefile 中的命令来更新一个或多个目标 名称,其中名称通常是一个程序。如果没有 -f 选项, make 将查找 makefile GNUmakefile、makefile 和 Makefile, 按这个顺序。

make makefile 将实际执行您的“makefile”(因为它在手册页中的默认名称中列出)文件,尝试构建已经存在的“makefile”目标(因为您传递的参数)

您需要构建“chello”二进制文件,因此您必须输入:

make chello

或者:

make -f makefile chello

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-28
    • 2018-04-05
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多