制作文件依赖部分,要求有xh: yh?
在下面的(删减的)make 文件中,依赖项位于底部。这是我正在编写的实际 make 文件的一部分。在实际情况中,有一个头文件依赖于另一个头文件。
我无法在其他地方找到答案,所以...我是否需要在依赖项下的底部添加一行以达到“swap.h:other.h”的效果?
SRC = swap.c other.c etc
OBJ = swap.o other.o etc
EXE = swap
$(EXE): $(OBJ)
$(CC) $(CFLAGS) -o $(EXE) $(OBJ) -lm
## Dependencies
swap.o: swap.h other.h
other.o: other.h
谢谢!
In the following (cut down) make file, the dependencies are at the bottom. This is part of an actual make file that i am writing. In the real case there is a header file dependent on another header.
I haven't been able to find the answer elsewhere so... would i need to include a line at the bottom under dependencies to the effect of "swap.h: other.h"?
SRC = swap.c other.c etc
OBJ = swap.o other.o etc
EXE = swap
$(EXE): $(OBJ)
$(CC) $(CFLAGS) -o $(EXE) $(OBJ) -lm
## Dependencies
swap.o: swap.h other.h
other.o: other.h
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于如果
other.h
更改,即使第一个#include
是秒,也不会对swap.h
执行任何操作,所以简短的答案是否定的。...但是,如果某些 C 源代码包含
swap.h
并且 swap.h 包含other.h
,则 other.h 中的更改将影响所需的对象从上述 C 源生成。但是,通常情况下,您不想手动维护标头依赖项。这是费力且容易出错的。
有多种方法可以自动生成这些依赖项。
我可以推荐高级自动依赖生成论文。此方法并不完美,但它与 Makefile 所能达到的效果一样好。
Since there nothing to do for
swap.h
ifother.h
changes even if the first#include
s the seconds, the short answer is no.... But, if some C source includes
swap.h
and swap.h includesother.h
, a change in other.h will affect /the object needed to be generated from the said C source.Typically, however, you don't want to maintain your header dependency manually. It is laborious and error prone.
There are several ways for generating these dependencies automatically.
I can recommend the Advanced Auto-Dependency Generation paper. This method is not perfect, but it is as good as you can get with Makefiles.
以下是定义头文件之间依赖关系的一种方法:
如果修改
other.h
,则任何依赖于swap.h
的目标都会更新。Here's one way to define dependencies between header files:
If
other.h
is modified, any target which depends onswap.h
will get updated.