- 3
- 0
- 约7.09千字
- 约 14页
- 2019-10-12 发布于山东
- 举报
武汉大学计算机学院 李文海 lwhaymail@21 GNU Make简介 程序员通过Makefile创建代码生成的规则以便于生成。 规则包含的三个方面: 生成文件自身。当编译时该文件将被创建。 是形成最终可执行文件必需的过程。如将*.c与*.o通过规则关联起来,则*.o将通过*.c得到。 依赖性的列表。任意存在依赖的对象的前导对象在生成之初必需由Makefile指出其所依赖的对象。 一旦定义了依赖,则被依赖的对象的任意修改都将触发依赖对象相应的变化。 一、简单的Makefile # ?all? is the default target. Simply make it point to myprogram all: myprogram # Define the components of the program, and how to link them together my program: io.o init.o compute.o gcc -o myprogram io.o init.o compute.o # Define the dependencies and compile information for the three C source code files compute.o: compute.c gcc –Wall –c –o compute.o compute.c init.o: init.c mycompute.h gcc –Wall –c –o init.o init.c io.o: io.c myprogram.h gcc –Wall –c –o io.o io.c 要素说明 目标文件名由all指示,如上例中的myprogram 冒号左边的项和右边的项具有相同的更新时间,或更近的更新时间 目标文件myprogram与三个目标文件相关联。如果任何一个文件比最终的可运行文件新,那么最终的可运行文件将被重新创建,否则没有必要执行该步 目标文件均有一个入口,用于指明与C文件的依赖性 $ make gcc –Wall –c –o io.o io.c gcc –Wall –c –o init.o init.c gcc –Wall –c –o compute.o compute.c gcc –o myprogram io.o init.o compute.o 若未更新任意目标执行make将无效 二、更巧妙的Makefile 上述Makefile存在的主要问题: gcc命令行选项和每个C源文件设定的依赖性被重复设置 解决方法:使用变量 过程: 使用等号(=)把左边的变量名和右边的变量值分开 在make中,语法上使用$(VARIABLE)获得括号中VARIABLE的值 变量Makefile # Line starting with the pound sign are comments: CC=gcc CFLAGS=-Wall COMPILE=$(CC) $(CFLAGS) –c # ?all? is the default target. Simply make it point to myprogram. all: myprogram #Define the components of the program, and how to link them together. myprogram: io.o init.o compute.o $(CC) –o myprogram io.o init.o compute.o # Define the dependencies and compile information for the three C source code files. compute.o: compute.c $(COMPILE) –o compute.o compute.c init.o: init.c myprogram.h $(COMPILE) –o init.o init.c io.o: io.c myprogram.h $(COMPILE) –c –o io.o io.c 要素说明 若需要添加选项,只需修改CC、CFLAGS和COMPILE COMPILE变量取决于其他两个变量的值 问题:每个C文件的编译项均明确写出 # Lines starting with the pound sign are comments. CC=gcc CFLAGS=-Wall COMPILE=$(CC) $(CFLAGS) –c # ?all? is the default target. Simply make it point to myprogram. all: mypro
您可能关注的文档
- 面向对象程序设计课后答案.doc
- JAVA程序设计第4章.ppt
- JAVA程序设计第5章.ppt
- JAVA程序设计第6章.ppt
- JAVA程序设计第9章.ppt
- JAVA程序设计第10章.ppt
- JAVA程序设计第11章.ppt
- JAVA程序设计第12章.ppt
- 武汉大学计算机学院linux复习题.doc
- Linux原理及应用——专题0:Shell实例 .ppt
- 河北盐山中学等校2025-2026学年上学期高三一模化学试卷(含解析).docx
- 河北正定中学2025-2026学年高一上学期期末考试物理试卷(含解析).docx
- 河北张家口市怀安县2025-2026学年第一学期期末教学综合评价八年级地理试卷(含解析).docx
- 河南安阳市殷都区2025-2026学年第一学期期末教学质量检测七年级地理试卷(含解析).docx
- 河南安阳市滑县2025一2026学年第一学期期末学业质量监测八年级地理试题(含解析).docx
- 河南安阳市林州市2025-2026学年上学期期末考试高一政治试题(含解析).docx
- 河南焦作市武陟县第一中学2025-2026学年高一上学期1月月考语文试卷(含解析).docx
- 河南济源市2025-2026学年上学期期末学业质量调研七年级历史试卷(含解析).docx
- PICC导管并发症的紧急处理与护理.pptx
- 河南鹤壁市2025-2026学年高二上学期期末考试生物试题(含解析).docx
最近下载
- C-V2X与单车智能融合研究.pptx VIP
- 消防改造设计任务书.docx VIP
- 广东省佛山市顺德区2024-2025学年六年级下册期中考试语文试卷(有答案).pdf VIP
- 消防设计任务书.docx VIP
- 实施指南《GB12268-2012危险货物品名表》实施指南.pptx VIP
- 带电作业安全距离PPT课件.pptx VIP
- 林业成果图制作—林业专题图及制图(GIS制图技术).pptx
- 高中英语课件7开课名师-郭贝老师from page to screen.pdf VIP
- 丙种球蛋白被动免疫治疗原因不明性反复自然流产研究.pdf VIP
- (二模)南通市2025届高三第二次调研测试英语试卷(含标准答案).docx
原创力文档

文档评论(0)