Makefile脚本无法正常运行

时间:2017-08-29 16:28:28

标签: makefile

我有这些文件main.cfun.cfun.h。我想使用makefile脚本来代替传统的编译方法。发布以下makefile脚本的人说这个脚本将自动捕获同一目录中的文件名,所以我需要的是导航到项目目录并写入终端$ make。我创建了一个文件makefile并放入以下脚本:

TARGET = prog
LIBS = -lm
CC = gcc
CFLAGS = -g -Wall

.PHONY: default all clean

default: $(TARGET)
all: default

OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)

%.o: %.c $(HEADERS)
    $(CC) $(CFLAGS) -c $< -o $@

.PRECIOUS: $(TARGET) $(OBJECTS)

$(TARGET): $(OBJECTS)
    $(CC) $(OBJECTS) -Wall $(LIBS) -o $@

clean:
    -rm -f *.o
    -rm -f $(TARGET)

但是,我收到此错误: make: *** No rule to make target缺省&#39 ;. Stop.`

我尝试了$make -v并得到了:

GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

我想我误解了他!那么,这里缺少什么?谢谢

1 个答案:

答案 0 :(得分:2)

缺少的分隔符错误是因为您没有使用“配方”选项卡。

例如,你的TARGET目标有一个$(OBJECTS)的先决条件,一旦Make知道那里(或使它),那么它将继续进行配方。

    $(TARGET): $(PREREQUISITES)
    ->(TAB) $(RECIPE)
相关问题