簡體   English   中英

Makefile:無規則可作為目標

[英]Makefile: no rule to make target

我正在遵循有關makefile的指南,但是最后一個示例我完全不理解,並且由於出現錯誤make: *** No rule to make target "obj/date.o", needed by "Whatsapp". Stop. ,我無法使makefile工作make: *** No rule to make target "obj/date.o", needed by "Whatsapp". Stop. 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不會自動執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM