欢迎来到天天文库
浏览记录
ID:46479394
大小:134.50 KB
页数:15页
时间:2019-11-24
《【精品】Linux程序设计基础实验指导》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Linux程序设计基础一C环境一VI编辑器的使用使用VI编辑下列几个函数文件:hello.hstarfun.hhello.cstaccStarfun.h文件内容如下:/*****starfunh*****/#ifndefSTARFUN_H#dcfincSTARFUN_H#defineNUM4#defineNUMBER3intstarl(){intij.k;for(k=l;k<=NUM;++k){for(i=l;i<=(NUM-k);++i)pnntfC1");for(j=l;j<=(2*k-l);++j)print"*”);printf(uH);)re
2、turn0;}intstar2(){inti,j,k;for(k=NUMBER;k>=0;-k){for(i=1;i<=(NUMBER-k+1);++i)printf(-“);for(j=l;j<=(2*k-l);++j)print”*”);printf(u");}return0;#endifhello.h文件内容如下:/*hello.h*/#ifndefHELLO.H#defineHELLOHvoidhello(){star1();printf(''hello,myfriends");)#endifhello.c文件内容如下:voidshowhe
3、llo(){hello();}star.c文件内容如下:#includc"starfun.hn#include"hello.h"#includeintmain(){star1();star2();showhello();return0;}Vi编辑器的使用,可以参考PPT,在使用Vi编辑器的过程中,注意使用Vi的-单行和多行复制命令,练习字符串查找替换命令,删除一个字符,删除光标后整个内容命令,删除一行命令,恢复删除,保存和退出命令筹命令,并尝试使用英他命令。掌握#ifndefSTARFUN.H#defineSTARFUN_H的宏定义用法二
4、.使用gCC编译器,编译程序第一种方法:分步进行1.illstar.cstarfun.h文件生成star.o目标文件gcc-cstar.c-ostar.o2.illhello.chello.hstarfun.h生成hello.o目标文件gcc-chello.c-ohello.o3.由hello.ostar.o生成应用程序myproggccstar.ohello.o-omyprog[root@localhost01_helloJ#./myprog****rTwrT^rT^rY*rjwrT*rTwrTwrTw****vl#"卜・p9n・p9nhello,myf
5、riends第二种方法:一条命令完成以上操作gccstacchello.c-omyprog结合本次课的PPT关于gcc部分,体会gcc编译器编译的过程,并在实验报告中描述在以上编译中尝试[root@localhost01_hcllo]#gccstar.chcllo.c-omyprog[root@localhostOl^hello]#gcc-wstarehello.c・omyprog[root@localhost01_hello]#gcc-Wallstar.chello.c-omyprogInfileincludedfromstar.c:1:starfun.
6、h:Infunction"starl1:starfun.h:13:warning:implicitdeclarationoffunctionxprintfstar.c:Infunction"main1:star.c:8:warning:implicitdeclarationoffunction'showhello'hello.c:Infunction"showhello1:hello.c:4:warning:implicitdeclarationoffunction、hello°体会・Wall・w选项的作用查阅当前的gcc版本命令[root@localho
7、st01_hello]#gcc-vReadingspecsfrom/usr/lib/gcc-lib/i386-redhat-linux/3.2>2/specsConfiguredwith:../configure-prefix=/usr—mandir=/usr/share/man—infodir=/usr/share/info-enable-shared・-enable-threads=posix-disable-checking-with-system-zlib・-enable-—cxa_atexit—host=i386-redhat-IinuxThre
8、admodel:posixgccversion3222003022
此文档下载收益归作者所有