第七章多模块软件的编译和链接.ppt
《第七章多模块软件的编译和链接.ppt》由会员分享,可在线阅读,更多相关《第七章多模块软件的编译和链接.ppt(37页珍藏版)》请在三一文库上搜索。
1、多模块软件的编译和链接,第7章,预习检查,$make f 文件,是什么文件? 遵循makefile语法的文件,也就是makefile文件 目标列表: 关联性列表,含义是什么? 目标列表依赖于关联性列表 简单变量的定义方式? 变量名 := 文本 举一个make内置变量的例 CFLAGS, $,$?等 make clean,clean常见的含义是什么? clean是虚目标,删除make生成的文件,2,本章目标,了解Make实用程序的功能 使用makefile管理多模块软件 掌握makefile的规则,变量 掌握makefile的虚目标规则,本章结构,简介,多模块软件的编译和链接,Makefile和
2、Make Rules,默认规则,虚目标,特殊目标,一般性语法错误及其纠正措施,多模块软件、依赖树和make,Make实用程序,make实用程序对简单变量的支持,内建变量,命令行的使用和调试,1-1 多模块软件,实用的软件都是拥有多个源文件 这些源文件称之为模块 多模块软件 多模块软件,2-1make,一个差强人意的办法 使用shell脚本 上述的缺点,导致了make的产生。,$cat build.sc gcc c prog1.c prog2.c prog3.c gcc o prog prog1.o prog2.o prog3.o,2-1make,Make的产生,2-1make,管理多模块程序的
3、编译和连接 读取一个说明文件-Makefile 描述系统中各模块的依赖关系 make使重编译的次数达到最小化 Makefile描述的依赖关系 各组件文件的时间戳 Makefile 实质上是一种脚本语言,2-1Make,2-1make,2-1makefile,目标列表: 关联性列表 命令列表,目标列表: 关联性列表; 命令列表,也称为先决条件,2-1makefile,注释 # 连接符 关联列表和命令列表中使用shell通配符 ? * ,与shell脚本的相同,2-1makefile,实例,源码 power.c #include #include main() float x,y; printf(
4、“the program take x and from stdin and displays xy.n“); printf(“enter number x:“); scanf(“%f“, ,$cat Makefile Sample makefile for the power program Remember:each command line starts with a TAB power:power.c gcc power.c -o power lm $,制表符,2-2依赖树,把power.c分成两个文件,#include double compute(double x,double y
5、); main() float x,y; printf(“the program take x and from stdin and displays xy.n“); printf(“enter number x:“); scanf(“%f“, ,#include double compute(double x,double y) return(pow(double)x,(double)y); ,2-2依赖树,power.o,compute.o,power:power.o compute.o gcc power.o compute.o -o power -lm,2-2依赖树,power.o,c
6、ompute.o,power:power.o compute.o gcc power.o compute.o -o power -lm power.o:power.c gcc c power.c compute.o:compute.c gcc c compute.c,power.c,compute.c,$make gcc -c power.c gcc -c compute.c gcc power.o compute.o -o power lm,树中节点的处理是自底向上的,由叶结点的父节点开始,2-2makefile,当目标文件比关联文件更新 更新关联文件,对比,$touch powerC $m
7、ake gcc power.c o power lm,仅仅只更新文件的修改时间为当前时间,目标文件存在,且比关联文件更新,重新编译更新的关联文件,2-2依赖树,进一步分成六个文件,建立依赖树,$cat computec include include”computeh” double compute(double x,double y) return(pow(double)x,(double)y);,$cat main.h /*Declaration of prompts to users */ const char *PROMPTl=”Enter the value of x:”; cons
8、t char *PROMPT2=”Enter the value of y:”;,$cat inputC # include”inputh” double input(const char *s) floatx; printf(”s”,s); scanf(“f”,&x); return(x); ,$cat input.h /* Declaration of the”input”function*/ double input(char*);,cat computeh /* Declaration of the“compute”function*/ double compute(double,do
9、uble);,2-2依赖树,$cat mainc #include #include”mainh” #include”computeh” #include”inputh” main() double x,y; printf(”The program takes X and Y from stdin and displays xy.n”); x=input(PROMPTl); y=input(PROMPT2); printf(”xy is:6.3fn”,compute(x,y); ,2-2依赖树,$cat mainc #include #include”mainh” #include”compu
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 第七 模块 软件 编译 链接
链接地址:https://www.31doc.com/p-2121052.html