Makefile:没有规则来制作目标

时间:2017-02-03 14:57:33

标签: c makefile

我正在关注makefile这个指南,但我完全不理解最后一个例子,因为我得到了错误make: *** No rule to make target "obj/date.o", needed by "Whatsapp". Stop.

这是我的makefile:

IDIR = ../include
CC = gcc
CFLAGS = -I$(IDIR)

ODIR = obj
LDIR = ../lib

LIBS = -lncurses

# Keep the alphabetical order!
_DEPS = \
constants.h\
date.h\
inOut.h\
languages.h\
message.h\
mycurses.h\
mysocket.h\
text.h\
time.h\
user.h\

DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

# Keep the alphabetical order!
_OBJ = \
date.o\
inOut.o\
languages.o\
main.o\
message.o\
mycurses.o\
mysocket.o\
text.o\
time.o\
user.o\

OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

# these two lines should tell the compilator that my .o files depend by .c files, don't they?
$(ODIR)/%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

Whatsapp:   $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean:
    rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ 

显然,我所有*.c都在当前文件夹中,所以我真的不知道我错过了什么。

为了更加清晰,以下是当前文件夹的内容:

urbijr@urbijr-VirtualBox:/media/sf_Whatsapp_CLIENT$ ls
constants.h  indexbook.txt  languages.c  makefile              message.h    mycurses.h  text.c  time.h
date.c       inOut.c        languages.h  message.c             message.txt  mysocket.c  text.h  user.c
date.h       inOut.h        main.c       message_for_user.txt  mycurses.c   mysocket.h  time.c  user.h

1 个答案:

答案 0 :(得分:3)

您的依赖关系不像您在makefile中指定的那样。下面的行指定所有包含文件应位于目录$(IDIR)

DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

这被设置为../include,但似乎您将所有头文件放在同一目录中。将它们移至../include或将IDIR更改为.(当前目录)。

您还需要创建输出目录(obj),因为我们不会自动执行此操作。