英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论