他们在 Makefile 的文档中是否指定了两次编译?

huangapple go评论76阅读模式
英文:

Are they specifying the compilation twice in the makefiles documentation?

问题

我正在学习如何使用make,在阅读文档时看到了这个示例

objects = main.o kbd.o command.o display.o \
          insert.o search.o files.o utils.o

edit : $(objects)
        cc -o edit $(objects)
main.o : main.c defs.h
        cc -c main.c
kbd.o : kbd.c defs.h command.h
        cc -c kbd.c
command.o : command.c defs.h command.h
        cc -c command.c
display.o : display.c defs.h buffer.h
        cc -c display.c
insert.o : insert.c defs.h buffer.h
        cc -c insert.c
search.o : search.c defs.h buffer.h
        cc -c search.c
files.o : files.c defs.h buffer.h command.h
        cc -c files.c
utils.o : utils.c defs.h
        cc -c utils.c
clean :
        rm edit $(objects)

关于edit目标,我正在使用Java和make,所以可能是我不知道的编译差异,但当我只在edit的第一行指定一次对象时,它会进入我为这些对象设置的每个规则并运行编译,那么为什么edit规则还有另一行来编译这些对象呢?文档是在进行两次编译,还是有特定的区别?

英文:

I am learning how to use make, and while reading the documentation saw this example:

objects = main.o kbd.o command.o display.o \
          insert.o search.o files.o utils.o

edit : $(objects)
        cc -o edit $(objects)
main.o : main.c defs.h
        cc -c main.c
kbd.o : kbd.c defs.h command.h
        cc -c kbd.c
command.o : command.c defs.h command.h
        cc -c command.c
display.o : display.c defs.h buffer.h
        cc -c display.c
insert.o : insert.c defs.h buffer.h
        cc -c insert.c
search.o : search.c defs.h buffer.h
        cc -c search.c
files.o : files.c defs.h buffer.h command.h
        cc -c files.c
utils.o : utils.c defs.h
        cc -c utils.c
clean :
        rm edit $(objects)

My question is on the edit target. I am using make with Java so it may be a compilation difference I'm not aware of, but when I just specify the objects once on the first line of edit it goes to each of the rules I set up for those objects and runs the compilation, so why does the edit rule have another line to compile those objects? Is the documentation just compiling it twice or is there a specific difference?

答案1

得分: 0

经过再次查看代码,我意识到他们正在从创建的对象中创建一个可执行文件,非常酷,哈哈!

编辑:

如果您尝试对Java项目使用make,请考虑使用诸如Gradle之类的构建工具,它可以更轻松地进行编译和测试。

英文:

After taking another look at the code, I realized that they are creating an executable from the created objects, pretty cool haha!

EDIT:

If you are trying to use make for java projects, consider using build tools such as gradle, it makes compilation and testing much easier.

huangapple
  • 本文由 发表于 2020年10月18日 09:24:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/64408855.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定