Makefile 不处理所有命令

Makefile not processing all commands

我试图通过首先预处理然后编译,然后组装然后链接逐步将 hello.c 转换为 hello。然而,只有我的 makefile 的第一条命令被执行:

Osheens-MacBook-Air-1115:Assignment0.1 osheensachdev$ ls
hello.c     makefile
Osheens-MacBook-Air-1115:Assignment0.1 osheensachdev$ cat makefile

hello.i : hello.c
    gcc -E hello.c -o hello.i

hello.s : hello.i
    gcc -S hello.i -o hello.s

hello.o : hello.s
    gcc -c hello.s -o hello.o

hello : hello.o
    $ld hello.o -e main hello

clean:
    rm hello.i hello.s hello.o hello
Osheens-MacBook-Air-1115:Assignment0.1 osheensachdev$ make
gcc -E hello.c -o hello.i
Osheens-MacBook-Air-1115:Assignment0.1 osheensachdev$ make
make: `hello.i' is up to date.

我在网上搜索了有关链接文件的信息,但没有找到任何关于为什么这不起作用的具体信息。

我还指定了 target: [dependancies] 所以我不明白为什么这不起作用。

Makefile 的第一个目标是默认目标。

这就是为什么您在许多 Makefile 中看到顶部有一个 all 目标,目的是 "make everything":

all: build test

build: <prerequisites>

test: <prerequisites>

由于您没有指定一个,因此只构建 hello.i(加上构建此目标所需的一切):

  1. hello.i 还不存在。
  2. hello.i 需要 hello.c。先做hello.c.
  3. hello.c 已经是 "made"。无事可做。
  4. 现在制作 hello.i 即 运行 gcc -E hello.c -o hello.i.
  5. 停止

然后你运行重新制作(没有任何特定目标)

  1. hello.i 已经存在。无事可做。
  2. 停止。

我怀疑你想制作 "hello",即你的程序。

或者:

  1. 将 "hello" 移到顶部并将其设为默认目标
  2. 或运行make hello