第七章多模块软件的编译和链接.ppt

上传人:sccc 文档编号:5147780 上传时间:2023-06-08 格式:PPT 页数:44 大小:813.01KB
返回 下载 相关 举报
第七章多模块软件的编译和链接.ppt_第1页
第1页 / 共44页
第七章多模块软件的编译和链接.ppt_第2页
第2页 / 共44页
第七章多模块软件的编译和链接.ppt_第3页
第3页 / 共44页
第七章多模块软件的编译和链接.ppt_第4页
第4页 / 共44页
第七章多模块软件的编译和链接.ppt_第5页
第5页 / 共44页
点击查看更多>>
资源描述

《第七章多模块软件的编译和链接.ppt》由会员分享,可在线阅读,更多相关《第七章多模块软件的编译和链接.ppt(44页珍藏版)》请在三一办公上搜索。

1、多模块软件的编译和链接,第7章,预习检查,$make f 文件,是什么文件?遵循makefile语法的文件,也就是makefile文件目标列表:关联性列表,含义是什么?目标列表依赖于关联性列表简单变量的定义方式?变量名:=文本举一个make内置变量的例CFLAGS,$,$?等make clean,clean常见的含义是什么?clean是虚目标,删除make生成的文件,2,本章目标,了解Make实用程序的功能使用makefile管理多模块软件掌握makefile的规则,变量掌握makefile的虚目标规则了解autoconf的原理和用法,本章结构,简介,多模块软件的编译和链接,Makefile和

2、Make Rules,默认规则,虚目标,特殊目标,一般性语法错误及其纠正措施,autoconf,多模块软件、依赖树和make,Make实用程序,make实用程序对简单变量的支持,内建变量,命令行的使用和调试,1-1 多模块软件,实用的软件都是拥有多个源文件这些源文件称之为模块多模块软件多模块软件,2-1make,一个差强人意的办法使用shell脚本上述的缺点,导致了make的产生。,$cat build.scgcc c prog1.c prog2.c prog3.cgcc 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 main()float x,y;printf(“the program take x and fr

4、om stdin and displays xy.n”);printf(“enter number x:”);scanf(“%f”,$cat MakefileSample makefile for the power programRemember:each command line starts with a TABpower:power.cgcc power.c-o power lm$,制表符,2-1makefile,当目标文件比关联文件更新更新关联文件,对比,$makemake:poweris up to date,$touch powerC$makegcc power.c o powe

5、r lm,仅仅只更新文件的修改时间为当前时间,目标文件存在,且比关联文件更新,重新编译更新的关联文件,2-2依赖树,把power.c分成两个文件,#cat power.c#include double compute(double x,double y);main()float x,y;printf(”The program takes x from stdin and displays xy.n”);printf(”Enter number x:”);scanf(”f,&x);printf(”Enter number y:”);scanf(”f,&y);printf(”xy is:63fn”

6、,compute(x,y);,#cat compute.c#includedouble compute(double x,double y)return(pow(double)x,(double)y);,2-2依赖树,power.o,compute.o,power:power.ocompute.ogcc power.o compute.o-o power-lm,2-2依赖树,power.o,compute.o,power:power.ocompute.ogcc power.o compute.o-o power-lmpower.o:power.cgcc c power.ccompute.o:c

7、ompute.cgcc c compute.c,power.c,compute.c,$makegcc-c powercgcc-c computecgee powero computeo-o powerlm,树中节点的处理是自底向上的,由叶结点的符节点开始,2-2依赖树,进一步分成六个文件,建立依赖树,$cat computecincludeinclude”computeh”double compute(double x,double y)return(pow(double)x,(double)y);,$cat main.h/*Declaration of prompts to users*/c

8、onst char*PROMPTl=”Enter the value of x:”const 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”functi

9、on*/double compute(double,double);,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 makefilepower:main.o input.o

10、 compute.o gcc main.o input.o compute.o-o power-1mmain.o:main.c main.h input.h compute.h gcc-c main.cinput.o:input.c input.h gcc-c input.ccompute.o:compute.c computeh gcc-c compute.c$,$makegcc-c main.cgcc-c input.cgcc-c compute.cgcc main.o input.o compute.o-o power-1m,1.第一个先决条件不存在,或者先决条件作为目标文件的先决条件更

11、新。生成第一个2.当所有的先决条件更新后,生成最终目标文件,2-3默认模式规则,-默认的后缀规则SUFFIXES:ocs.c.o:$(CC)$(CFLAGS)-c$.s.o:$(AS)$(ASFLAGS)-o$,-默认的模式规则(gnu Make)%.o:%.c:$(CC)$(CFLAGS)-c$%.o:%.s$(AS)$(ASFLAGS)-o$,-利用默认的规则修改后的makefile$cat makefilepower:main.o input.o compute.ogcc main.o input.o compute.o-o power-lmmain.o:main.h input.h c

12、ompute.hinput.o:input.hcompute.o:compute.h,内置变量,以后会经常遇到,阶段总结,为什么使用make?Makefile的语法规则依赖树的分析默认的模式规则,2-4简单变量,简单变量定义:变量名:=文本添加:变量名+=文本引用$(变量名)$变量名$单字符变量,C=gcc$C,见过其他的模式吗?变量名=文本变量名?=文本超出了本章的返回,2-4简单变量,$cat makefileCC:=gccOPTIONS:=-O3OBJECTS:=main.o OBJECTS+=input.o compute.oSOURCES:=main.c inputc compute

13、.cHEADERS:=main.h input.h compute.hpower:$(OBJECTS)$(CC)$(OPTIONS)-o power$(OBJECTS)-lmmain.o:mainh inputh computehinput.o:inputhcompute.o:computehpower.tar:makefile$(HEADERS)$(SOURCES)tar-cvf power.tar makefile$(HEADERS)$(SOURCES)clean:rm*.o$,2-5 内置变量,2-5修改后的makefile,complete:powerecho”Build comple

14、te”power:$(OBJECTS)$(CC)$(OPTIONS)-O$-lmecho”The executable is in the power file”main.o:main.h input.h compute.hcompute.o:compute.hinput.o:input.hpower.tar:makefile$(HEADERS)$(SOURCES)tar-cvf$clean:rm-f*.o core power,虚目标,2-6虚目标,不存在的文件,而且也无需创建他们允许你强制执行某些事件,而这些事件在正常规则中是不会发生的规则虚目标和先决条件如果虚目标作为先决条件使用,它必须

15、作为目标出现在某处虚目标总是使与之有关的命令被执行虚目标作为先决条件,总是是相应的目标重建,2-6虚目标,常见虚目标列表,2-6虚目标,$cat makefileINSTALLDIR=/home/sarwar/courses/bininstall:client servercp f$(INSTALLDIR)rm f*.o$cd$(INSTALLDIR);chmod 755$uninstall:cd$(INSTALLDIR);rm client server client:client.o miscc.o rcopyc.ogcc client.o miscc.o rcopyc.o lnsl-o

16、client client.o:client.c netc.h rcopy.h gcc-c clientc$make install.,1.不存在的文件,仅为完成某些功能2.如果目录下存在这个同名文件会出现什么情况?,2-7特殊目标,上述问题用.PHONY的特殊目标解决.PHONY:cleanclean:rm rf*.o,2-7特殊目标,2-8一般性语法错误,Tab键在和换行符插入了空格,$makeMakefile:4:*missing separator.Stop$cat t Makefile$grep Makefile,$cat e Makefile$grep$Makefile,2-9命令

17、行的使用和调试,使用非标准的Makefile名称从标准输入读取显示所执行的顺序,$make f prog1.makefile,$make-f-,$make-n,3-1autoconf,创建安装shell脚本的工具configure一旦configure生成,无需autoconfAutoconf打包的软件./configuremakemake install,3-1autoconf,Autoconf 实际上是个工具集,3-1autoconf,确定条件编译$ifnames*.c*.h输出为条件定义的宏的列表,以及定义他们的文件创建configure.in文件$autoscan$move confi

18、gure.scan configure.in,3-1autoconf,编辑configure.in文件由m4宏指示字组成被autoconf解析,生成configure脚本创建makefile.in文件修改自己的makefile文件来包含autoconf产生的定义,任务的主要部分,3-1autoconf,创建config.h.in文件$autoheaderconfig.h文件的输入更新源文件所有的考虑移植的源文件,需要包含config.h,3-1autoconf,创建安装脚本$autconf复制autoconf脚本Autoconf 的其他脚本config.guessConfig.subInsta

19、ll-sh包含在目录/usr/lib/autoconf中,阶段总结,Makefile 简单变量的定义Makefile的内置变量虚目标与常用虚目标Makefile常见的语法错误Autoconf 打包软件的安装用autoconf打包软件,本章总结,简介,多模块软件的编译和链接,Makefile和Make Rules,默认规则,虚目标,特殊目标,一般性语法错误及其纠正措施,autoconf,多模块软件、依赖树和make,Make实用程序,make实用程序对简单变量的支持,内建变量,命令行的使用和调试,多模块软件编译的困境,分析make的原理,make程序的用法,以及Makefile的语法,规则,以及

20、makefile对变量的支持,描述了虚目标,以及makefile的语法错误检查方法,描述了autoconf打包软件的安装,以及如何用autoconf打包软件,实验,任务1:为hello world 编写makefile任务2:autoconf的简单应用,任务1,注意事项提示1:编写一个头文件,两个C文件main.c 是主程序hello.c编写打印”hello,world”的函数提示2:编写makefile,建立直接的依赖关系使用默认规则定义变量CROSS_COMPILE:=CC:=(CROSS_COMPILE)gcc,任务2,确认系统中存在autoscan,autoconf命令编写hello.c以及makefile,44,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 农业报告


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号