gpt4 book ai didi

c - Makefile 说明 : files that includes headers which includes another header

转载 作者:行者123 更新时间:2023-11-30 16:55:14 24 4
gpt4 key购买 nike

当我的程序包含一个包含另一个 header 的 header 时,会发生什么情况?例如,main.c 包含 header1.h,header1.h 包含 header2.h。我的 makefile 应该是:

main.x: main.o
gcc -o main.x

main.o: main.c header1.h header2.h
gcc -c main.c

或者是否有必要包含 header2.h?

main.x: main.o
gcc -o main.x

main.o: main.c header1.h
gcc -c main.c

或者根本没有必要包含任何 header ?

main.x: main.o
gcc -o main.x

main.o: main.c
gcc -c main.c

最佳答案

在 Makefile 中列出依赖项的目的是让 make 知道在什么情况下需要重建。如果自构建目标以来列出为依赖项的文件已被修改,则需要重新构建目标。因此,最好列出在构建目标的过程中引用的所有文件。

如果你没有列出一个小时包含的文件,那么一切仍然有效 - 直到你编辑你没有告诉make的文件,此时你会发现make 可能不会费心重新编译。

关于c - Makefile 说明 : files that includes headers which includes another header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40352910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com