为什么这个 makefile 模式规则不匹配?

huangapple go评论67阅读模式
英文:

Why doesn't this makefile pattern rule match?

问题

以下是您要翻译的部分:

我在我的项目中有以下结构

project
//obj
/


我在我的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&#39;t have llist.c in my sources directory. I still find the error a bit weird though. I mean: Why doesn&#39;t makefile report an error like ```make: *** No rule to make target &#39;llist.c&#39;, needed by &#39;obj/llist.o&#39;.  Stop.```? Would have saved me some hours

</details>



huangapple
  • 本文由 发表于 2023年8月10日 22:17:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定