理解Make的隐含规则
如果我从此文件中删除 gcc 行,难道不应该将编译作为隐式规则吗?为什么它不允许我使用该 makefile 配置运行程序 ./calc
?
生成文件:
all: calc
clean:
rm -rf calc arit.o calc.o
calc: calc.o arit.o
#gcc -o calc calc.o arit.o
calc.o: calc.c arit.h
#gcc -c calc.c
arit.o: arit.c arit.h
#gcc -c arit.c
If I erase the gcc lines from this file shouldn't it take compilation as the implicit rule? Why isn't it allowing me to run the program ./calc
with that makefile configuration?
Makefile:
all: calc
clean:
rm -rf calc arit.o calc.o
calc: calc.o arit.o
#gcc -o calc calc.o arit.o
calc.o: calc.c arit.h
#gcc -c calc.c
arit.o: arit.c arit.h
#gcc -c arit.c
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于注释由制表位缩进,因此它被视为命令(并由 shell 执行,shell 将其视为注释)。
如果“#”符号位于第 1 列,那么它们将是纯(make)注释。
Because the comment is indented by a tab stop, it is treated as a command (and executed by the shell, which treats it as a comment).
If the '#' symbols were in column 1, then they would be pure (make) comments.
根据 Jonathan Leffler 的回答,以下最小的 GNUMakefile 应该仅通过隐式规则进行所有编译和链接:
Further to Jonathan Leffler's answer, the following minimal
GNUMakefile
should do all compilation and linking through implicit rules only: