我正在遵循有关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
您的依存关系与您在中指定的不一样makefile
。下面的行指定所有包含文件应位于目录中$(IDIR)
。
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
设置为../include
,但是似乎所有的头文件都在同一目录中。将它们移动到../include
或更改IDIR
为.
(当前目录)。
您还需要创建输出目录(obj
),因为make不会自动执行此操作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句