英文:
Why doesn't this makefile pattern rule match?
问题
以下是您要翻译的部分:
我在我的项目中有以下结构
project
/
/
我在我的Makefile中有以下配方
```text
ALL_OBJ := obj/malloc.o obj/ll.o obj/llist.o obj/socket.o obj/util.o obj/event.o
...
obj/%.o : ./%.c ./%.h
$(GCC) -g -c -o $@ $< -lpthread $(ALL_INC) $(CFLAGS) ${ADD_CLFAGS}
...
libshmsock.a : $(ALL_OBJ)
ar rcs libshmsock.a $^
它给我以下错误:
make: *** No rule to make target 'obj/llist.o', needed by 'libshmsock.a'. Stop.
为什么模式规则 obj/%.o
不能匹配 obj/llist.o
?
<details>
<summary>英文:</summary>
I have the following structure in my project
project
/<source-files>
/obj
/ <obj-files>
I have following receipe in my Makefile
ALL_OBJ := obj/malloc.o obj/ll.o obj/llist.o obj/socket.o obj/util.o obj/event.o
...
obj/%.o : ./%.c ./%.h
$(GCC) -g -c -o $@ $< -lpthread $(ALL_INC) $(CFLAGS) ${ADD_CLFAGS}
...
libshmsock.a : $(ALL_OBJ)
ar rcs libshmsock.a $^
And it gives me the following error:
make: *** No rule to make target 'obj/llist.o', needed by 'libshmsock.a'. Stop.
Why doesnt the pattern rule ```obj/%.o``` match ```obj/llist.o```?
</details>
# 答案1
**得分**: 0
我知道了,当我写问题的时候我明白了,但我想也许对某人有帮助。问题是我在我的源目录中没有llist.c。不过我仍然觉得这个错误有点奇怪。我的意思是:为什么makefile没有报告一个错误,类似于```make: *** No rule to make target 'llist.c', needed by 'obj/llist.o'. Stop.```?这会省下我一些时间。
<details>
<summary>英文:</summary>
Ok i got it while i wrote the question, but I thought maybe it helps someone. The Problem was that I didn't have llist.c in my sources directory. I still find the error a bit weird though. I mean: Why doesn't makefile report an error like ```make: *** No rule to make target 'llist.c', needed by 'obj/llist.o'. Stop.```? Would have saved me some hours
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论