在子文件夹中制作源问题
我有编译子文件夹中所有 *.c 文件的 makefile:
objects := $(patsubst %.c,%.o,$(wildcard *.c))
cobj: $(objects)
$(objects): %.o: %.c
$(CC) -c $< -o $@
我在尝试从父文件夹中执行相同操作时遇到问题。假设我的 .c 文件位于“csrc”文件夹中,
objects := $(addprefix, csrc/, $(patsubst %.c,%.o,$(wildcard *.c)))
cobj: $(objects)
$(objects): csrc/%.o: %.c
$(CC) -c $< -o $@
我总是看到“对 cobj 没什么可做的......有什么想法吗?
I have makefile that compiles all *.c files in subfolder:
objects := $(patsubst %.c,%.o,$(wildcard *.c))
cobj: $(objects)
$(objects): %.o: %.c
$(CC) -c lt; -o $@
I am having trouble trying to do the same from parent folder. Lets say my .c files are in the folder 'csrc'
objects := $(addprefix, csrc/, $(patsubst %.c,%.o,$(wildcard *.c)))
cobj: $(objects)
$(objects): csrc/%.o: %.c
$(CC) -c lt; -o $@
i always see "nothing to do for cobj... Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的模式规则
csrc/%.o: %.c
将例如csrc/foo.o
转换为foo.c
,而不是csrc /foo.c
。想必这不是您想要的。为什么不只是
%.o: %.c
呢?Your pattern rule
csrc/%.o: %.c
translates e.g.csrc/foo.o
intofoo.c
, notcsrc/foo.c
. Presumably, that is not what you want.Why not just
%.o: %.c
?奥利·查尔斯沃思说的是正确的,但还有一个错误。通配符函数仅检查当前目录。现在,
$(objects)
将为空(我假设当前父目录中没有源文件)。您必须指定路径:$(wildcard csrc/*.c)
What Oli Charlesworth said is correct, but there's another mistake. The wildcard function only checks the current directory. As it is now,
$(objects)
will be empty (I assume there are no source files in the current, parent directory). You will have to specify the path:$(wildcard csrc/*.c)