ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:185.10KB ,
资源ID:29483525      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/29483525.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Linux程序设计基础实验指导.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Linux程序设计基础实验指导.docx

1、Linux程序设计基础实验指导 Linux程序设计基础C环境一,使用Vi编辑器完成以下4个文件的内容输入:hello.hstarfun.hhello.cstar.cStarfun.h 文件内容如下:/*starfun.h*/#ifndef STARFUN_H#define STARFUN_H#define NUM 4#define NUMBER 3int star1() int i,j,k; for(k=1;k=NUM;+k) for(i=1;i=(NUM-k);+i) printf( ); for(j=1;j=0;-k) for(i=1;i=(NUMBER-k+1);+i) printf(

2、); for(j=1;j=(2*k-1);+j) printf(*); printf(n); return 0;#endifhello.h文件内容如下:/*hello.h*/#ifndef HELLO_H#define HELLO_Hvoid hello() star1(); printf(hello,my friendsn); #endifhello.c 文件内容如下:void showhello() hello();star.c文件内容如下:#include starfun.h#include hello.h#include int main() star1(); star2(); sho

3、whello(); return 0;Vi编辑器的使用,可以参考PPT和Vi.doc文档,在使用Vi编辑器的过程中,注意使用Vi的单行和多行复制命令,练习字符串查找替换命令,删除一个字符,删除光标后整个内容命令,删除一行命令,恢复删除,保存和退出命令等命令,并尝试使用其他命令。掌握#ifndef STARFUN_H #define STARFUN_H的宏定义用法二使用gcc编译器,编译程序第一种方法:分步进行1由star.c starfun.h 文件生成star.o 目标文件gcc -c star.c -o star.o2由hello.c hello.h starfun.h生成hello.o目

4、标文件gcc -c hello.c -o hello.o3由hello.o star.o 生成应用程序myproggcc star.o hello.o -o myprogrootlocalhost 01_hello# ./myprog * * * * * * * * *hello,my friends第二种方法:一条命令完成以上操作gcc star.c hello.c -o myprog结合本次课的PPT关于gcc部分,体会gcc编译器编译的过程,并在实验报告中描述在以上编译中尝试rootlocalhost 01_hello# gcc star.c hello.c -o myprogrootl

5、ocalhost 01_hello# gcc -w star.c hello.c -o myprogrootlocalhost 01_hello# gcc -Wall star.c hello.c -o myprogIn file included from star.c:1:starfun.h: In function star1:starfun.h:13: warning: implicit declaration of function printfstar.c: In function main:star.c:8: warning: implicit declaration of fu

6、nction showhellohello.c: In function showhello:hello.c:4: warning: implicit declaration of function hello体会-Wll -w选项的作用查阅当前的gcc版本命令rootlocalhost 01_hello# gcc -vReading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specsConfigured with: ./configure -prefix=/usr -mandir=/usr/share/man -infodir=

7、/usr/share/info -enable-shared -enable-threads=posix -disable-checking -with-system-zlib -enable-_cxa_atexit -host=i386-redhat-linuxThread model: posixgcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)三 使用动态库(1)rootlocalhost 01_hello# gcc -c -fpic hello.crootlocalhost 01_hello# lsamake hello.c hello

8、.h hello.o makefile_01 makefile_02 makefile_03 Makefile_rule star.c starfun.h(2)rootlocalhost 01_hello# gcc -shared -s -o libhello.so hello.o rootlocalhost 01_hello# lsamake hello.c hello.h hello.o libhello.so makefile_01 makefile_02 makefile_03 Makefile_rule star.c starfun.h注意libhello.so库文件的命名格式,(1

9、)(2)也可以用下边命令替代gcc -fpic -shared -s hello.c -o libhello.sorootlocalhost 01_hello# cp libhello.so /usr/lib 注意/usr/lib为用户库自动搜索路径rootlocalhost 01_hello# gcc -lhello star.c -o mystarrootlocalhost 01_hello# ldd mystar libhello.so = /usr/lib/libhello.so (0x4002d000) libc.so.6 = /lib/tls/libc.so.6 (0x420000

10、00) /lib/ld-linux.so.2 = /lib/ld-linux.so.2 (0x40000000)rootlocalhost 01_hello# ./mystar * * * * * * * * *hello,my friendsrootlocalhost 01_hello#四,使用静态库rootlocalhost 01_hello# rm *.orm:是否删除一般文件hello.o? yrootlocalhost 01_hello# rm mystar rm:是否删除一般文件mystar? yrootlocalhost 01_hello#rootlocalhost 01_hel

11、lo# rm libhello.*rootlocalhost 01_hello# gcc -c hello.c -o hello.orootlocalhost 01_hello# ar -rc libhello.a hello.orootlocalhost 01_hello# gcc star.c libhello.a -o mystarrootlocalhost 01_hello# ./mystar * * * * * * * * *hello,my friends五 调试器的使用1gdb进入02_gdb 目录执行rootlocalhost 02_gdb# gcc -g eg1.c -o e

12、g1rootlocalhost 02_gdb# gdb eg1GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)Copyright 2003 Free Software Foundation, Inc.GDB is free software, covered by the GNU General Public License, and you arewelcome to change it and/or distribute copies of it under certain conditions.Type show copying to see

13、 the conditions.There is absolutely no warranty for GDB. Type show warranty for details.This GDB was configured as i386-redhat-linux-gnu.(gdb) runStarting program: /home/qianzg/ARM2410DEMO/02_gdb/eg1 Program received signal SIGFPE, Arithmetic exception.0x0804833f in wib (no1=8, no2=8) at eg1.c:66 re

14、sult = no1 / diff; 参考“使用 GDB 调试 Linux 软件.htm ”使用gdb2在开发板上进行远程调试在开发板上/mnt/yaffs/explseg1 gdbserver myshell termeg2 hello pthread/mnt/yaffs/exp./eg1Floating point exception/mnt/yaffs/expgdbserver 192.168.0.199:1234 eg1Process eg1 created; pid = 121Remote debugging from host 192.168.0.199在PC上rootlocalh

15、ost 02_gdb# armv4l-unknown-linux-gdb eg1GNU gdb 5.2.1Copyright 2002 Free Software Foundation, Inc.GDB is free software, covered by the GNU General Public License, and you arewelcome to change it and/or distribute copies of it under certain conditions.Type show copying to see the conditions.There is

16、absolutely no warranty for GDB. Type show warranty for details.This GDB was configured as -host=i686-pc-linux-gnu -target=armv4l-unknown-linux.(gdb) target remote 192.168.0.191:1234 Remote debugging using 192.168.0.191:12340x40000d00 in ? ()(gdb) list3 4 int result, diff;5 diff = no1 - no2;6 result

17、= no1 / diff;7 return result;8 9 int main(int argc, char *argv)10 11 int value, div, result, i, total;12 value = 10;(gdb) info locals No symbol table info available.(gdb) break 17Breakpoint 1 at 0x2000424: file eg1.c, line 17.(gdb) continue Continuing. Breakpoint 1, main (argc=1, argv=0xbffffea4) at

18、 eg1.c:1717 result = wib(value, div);(gdb) info locals value = 10div = 6result = 1075053560i = 0total = 0(gdb) bt#0 main (argc=1, argv=0xbffffea4) at eg1.c:17(gdb)六,Makefile文件的编写1使用Makefile理论部分请参阅PPT和“熟悉Linux开发环境.doc”编写Makefile文件由该Makefile文件编译第一节中的hello.h starfun.h hello.c star.c 四个文件2使用automakeroot

19、localhost hello#vi hello.crootlocalhost hello# lshello.crootlocalhost hello# autoscan rootlocalhost hello# lsautoscan.log configure.scan hello.crootlocalhost hello# vi configure.scan rootlocalhost hello# lsautoscan.log configure.scan hello.crootlocalhost hello# mv configure.scan configure.inrootloca

20、lhost hello# lsautoscan.log configure.in hello.c rootlocalhost hello# vi configure.in rootlocalhost hello# aclocalrootlocalhost hello# lsaclocal.m4 autoscan.log configure.in hello.crootlocalhost hello# autoconf rootlocalhost hello# lsaclocal.m4 autom4te.cache autoscan.log configure configure.in hell

21、o.crootlocalhost hello# vi Makefile.am rootlocalhost hello# lsaclocal.m4 autom4te.cache autoscan.log configure configure.in hello.c Makefile.amrootlocalhost hello# automake -add-missing configure.in: installing ./install-shconfigure.in: installing ./mkinstalldirsconfigure.in: installing ./missingMak

22、efile.am: installing ./depcomprootlocalhost hello# lsaclocal.m4 autoscan.log configure.in hello.c Makefile.am missingautom4te.cache configure depcomp install-sh Makefile.in mkinstalldirsrootlocalhost hello# ./configure checking for a BSD-compatible install. /usr/bin/install -cchecking whether build

23、environment is sane. yeschecking for gawk. gawkchecking whether make sets $(MAKE). yeschecking for gcc. gccchecking for C compiler default output. a.outchecking whether the C compiler works. yeschecking whether we are cross compiling. nochecking for suffix of executables. checking for suffix of obje

24、ct files. ochecking whether we are using the GNU C compiler. yeschecking whether gcc accepts -g. yeschecking for gcc option to accept ANSI C. none neededchecking for style of include used by make. GNUchecking dependency style of gcc. gcc3configure: creating ./config.statusconfig.status: creating Mak

25、efileconfig.status: executing depfiles commandsrootlocalhost hello#makesource=hello.c object=hello.o libtool=no depfile=.deps/hello.Po tmpdepfile=.deps/hello.TPo depmode=gcc3 /bin/sh ./depcomp gcc -DPACKAGE_NAME= -DPACKAGE_TARNAME= -DPACKAGE_VERSION= -DPACKAGE_STRING= -DPACKAGE_BUGREPORT= -DPACKAGE=

26、hello -DVERSION=1.0 -I. -I. -g -O2 -c test -f hello.c | echo ./hello.cgcc -g -O2 -o hello hello.o rootlocalhost hello# ./hello Hello, GNU!rootlocalhost hello#关于configure.in的内容rootlocalhost hello# cat configure.in# -*- Autoconf -*-# Process this file with autoconf to produce a configure script. AC_INIT(hello.c)AM_INIT_AUTOMAKE(hello,1.0) # Checks for programs.AC_PROG_CC # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT(Makefile)

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1