我想寫一個Makefile,當我在應用程序中添加一些代碼時,我只需要更改DEPS_NAME變量,但是出現了一些錯誤,我找不出什麼。我知道這不是這個Makefile的唯一問題,我剛開始學習這個技術。Makefile:沒有規則使目標變量
這是我的項目結構
application/
├── deps/
│ ├── buffer/
│ │ ├── buffer.c
│ │ └── buffer.h
│ └── other/
│ ├── other.c
│ └── other.h
├── objs/
├── application.c
└── Makefile
這是我的Makefile
CC = gcc
APP_NAME = application
OBJS_PATH = objs
DEPS_PATH = deps
DEPS_NAME = buffer other
DEPS = $(patsubst %,$(OBJS_PATH)/%.o,$(DEPS_NAME))
$(OBJS_PATH)/%.o: $(DEPS_PATH)/%/%.c
$(CC) -o [email protected] -c $^
$(APP_NAME): $(DEPS)
$(CC) -o [email protected] [email protected] $^
all: $(APP_NAME)
這是當我鍵入做出錯誤:
make: *** No rule to make target `objs/buffer.o', needed by `application'. Stop.
如果'buffer.c'需要其他.h中的任何信息 - 或other.c需要buffer.h中的任何信息,那麼這個makefile在連接步驟中也會失敗。可以在makefile中使用當前文件/目錄體系結構,但如果所有頭文件都位於同一目錄中的目錄和所有源文件中,則編寫生成文件會更容易。 – user3629249
@ user3629249感謝您的建議,但問題並未出現,因爲代表是獨立的。 – wsknorth