在切换到某个目录之前,Make 会在该目录中寻找依赖项吗?
我尝试编写以下形式的 make
规则:
lib%.so: computations/%.h
make -C computations/ -f makefile $<
输出:
make -C computations/ -f makefile computations/test.h
make[1]: Entering directory `/home/shai/csm/csm2/src/computations'
make[1]: *** No rule to make target `computations/test.h'. Stop.
make[1]: Leaving directory `/home/shai/csm/csm2/src/computations'
make: *** [libtest.so] Error 2
嗯,看起来它在切换库后查找 %.h
。没什么大不了的,我只是尝试删除
lib%.so: %.h
make -C computations/ -f makefile $<
,但现在它根本不识别规则!
输出:
shai@ubuntu:~/csm/csm2/src$ make libtest.so
`make: *** No rule to make target `libtest.so'. Stop.
make
是在玩弄我的想法吗? 依赖关系的变化如何使其停止识别目标?
I tried to write a make
rule of this form:
lib%.so: computations/%.h
make -C computations/ -f makefile lt;
Output:
make -C computations/ -f makefile computations/test.h
make[1]: Entering directory `/home/shai/csm/csm2/src/computations'
make[1]: *** No rule to make target `computations/test.h'. Stop.
make[1]: Leaving directory `/home/shai/csm/csm2/src/computations'
make: *** [libtest.so] Error 2
Well, it seems that it looks for %.h
after switching library. No biggie, I'll just try removing
lib%.so: %.h
make -C computations/ -f makefile lt;
but now it doesn't recognize the rule at all!
Output:
shai@ubuntu:~/csm/csm2/src$ make libtest.so
`make: *** No rule to make target `libtest.so'. Stop.
Is make
playing with my mind? How could a change in the dependencies make it stop recognizing the target?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很可能是因为它找不到符合依赖关系模式的文件,因为
test.h
位于另一个目录中。您可以使用VPATH
让它搜索其他目录中的文件。编辑:但这仍然不能完全解决您的问题,因为
$<
将被computations/test.h
替换,在目录中找不到它计算
(如您遇到的第一个错误)。您可以尝试 $(notdir $<),但我认为这是一个丑陋的黑客(如果它有效;我还没有尝试过)。这是由 makefile 和项目结构的设计造成的。Most likely because it can't find a file that fits the pattern of the dependency, because
test.h
is in another directory. You could useVPATH
to have it search for files in other directories.Edit: but this still won't fix your problem completely, because
$<
will be substituted bycomputations/test.h
, which won't be found in the directorycomputations
(as in the first error you got). You might try$(notdir $<)
, but I think it's an ugly hack (if it works; I haven't tried it). This results from the design of your makefile and project structure.你使用的是错误的。
Make 的设计实际上相当简单:你告诉它
然后对依赖信息进行拓扑排序,以便以正确的顺序执行主体。
您使用
$<
的规则(扩展为依赖项列表)意味着您告诉调用的 make 创建依赖项%.h
而不是目标lib%.so
。规则必须创建目标。如果需要创建依赖项,您需要告诉 make 如何使用另一个单独的规则来创建依赖项,而不是尝试确保它在此规则中是最新的。
当您尝试跨目录进行协调时,我会推荐论文 Recursive make被认为是有害的,这通常是一种组织事物的好方法,尽管不是唯一可能的做事方式。
You're using make wrong.
Make's design is actually fairly simple at heart: you tell it
Make then topological sorts the dependency information so it executes the bodies in the right order.
Your rule with
$<
(which expands to the list of dependencies) means you're telling the invoked make to create the dependency%.h
not the targetlib%.so
.The rule has to create the target. If the dependency needs to be created, you need to tell make how to do so with another, separate rule, not try to ensure it is up to date in this rule.
As you're trying to coordinate across directories, I'll recommend the paper Recursive make considered harmful, which can often be a nice way to organize things, though not the only possible way to do things.
这可能只是您复制/粘贴它的方式,但您在第二种形式中缺少一个选项卡。
It might just be the way you copy/pasted it, but you're missing a tab in the second form.