我是大帅哥,擅长LINUX和C语言,还有脚本,希望和大家交朋友 mail:newhitler@163.com

《Make/Autoconf》练习题

上一篇 / 下一篇  2007-08-23 17:36:00 / 个人分类:C语言编程

gRX[xV7FM01)编程实现以下功能LUPA开源社区6J y^Qy
1.1)主程序hello.c(打印I love you qiu ming)
8jb^o"b"}01.2)主程序通过头文件head.h调用msg函数LUPA开源社区XA:dD$zClw4{(R@
1.3)头文件head.h(声明msg函数)
+BzRk1sDn;N^01.4)msg函数由msg.c定义(打印This is a message)LUPA开源社区"IhME5HR

LUPA开源社区y%_.{P-qE(|+?

LUPA开源社区2s5B]W!b?;J H
参考答案:

2\8s3b7XBV"d)Dro0

n0qD]*T.V0hello.c:
_9rR^U@(r {0# include <stdio.h>
!F~ M#j|l7GD-^0# include <stdlib.h>
_9n3G1QY6B)NY0# include <string.h>LUPA开源社区bw|,S+\}0_
# include "head.h"
f/ZO$UM1k%Ci7|0int main (int argc,char *argv[])
sq-| gN;_ u0{
+t)k*d:RX{6c2}0        printf("I love you qiu ming!\n");
6H(C3^V |$C&R2_u5~3|0        msg();
+B@u5a5ihG)`0        return 0;
!S A"N!t]9Vpo0}LUPA开源社区xR*G7~9C-`g

LUPA开源社区4IkOP#o

LUPA开源社区^I2} `3ol,E/V
head.h:LUPA开源社区5g6L2G;u t/K;X
void msg(void);

O3o&Ed.u0

AG ~NH/E^2@+Ma:L{0
_ T@,FhBP0msg.c:LUPA开源社区7S!n'b_Z8U
# include <stdio.h>

$Uv+~0QN b#e0 LUPA开源社区 Yzva[$RF+H,@0O

void msg (void)LUPA开源社区9_-B4W.N2pN u US
{LUPA开源社区9o oS$]Df]:Qj
        printf("This is a message!\n");
3nr!J(jEIv0}LUPA开源社区 `5W!j"P{ mM

GA*{0C9\m!gi{@ `0 

-O.Il,[`0W6R U _0 LUPA开源社区*T:tb2VUx yR

2)编程实现以下的功能:
eo)\8w3KMt02.1)主程序chen.c(打印I am chenkuo)

/VZ_jR hb${p#M0

"c oA+Nr0LUPA开源社区&}GtZ9u&\0p"i
参考答案:LUPA开源社区6w Ju ?Zd)W1a oP
chen.c:
3E,c\M8{ X"pX/d0# include <stdio.h>LUPA开源社区S,Tn4^%R~
int main (int argc,char *argv[])
!C0n/@$J#d0{LUPA开源社区)PGzcHW(W
        printf("I am chenkuo\n");LUPA开源社区F*E'a#zr N PM
        return 0;
6i)s x9z0^ ps0}LUPA开源社区UU8]'_+pwj

!^}*K p~+p0 LUPA开源社区)Y kG_b]k

LUPA开源社区]!y`]/|^ KBl


S-E)N"l l@)d-Z@03)承上题, 用makefile文件定义以上两个程序的编译链接过程
$m-j`Z ir03.1)定义编译hello为默认的目标体
0d)T3V YO9t03.2)定义编译chen目标体LUPA开源社区k`Z}1_5z.^v(d
3.3)定义msg.o和hello.o两个目标文件
'v"G3CSQY2f v&q03.4)定义笼统规则目标all,即编译hello和chenLUPA开源社区^ E aI-_)E2AB#wN
3.5)定义伪目标clean,即清除*.o和生成的可执行文件hello和chenLUPA开源社区3Q8U$P5BpD` L6DE

`-sZC#n"A1v2B^+X0LUPA开源社区x^3`h4v9\ u:nmH
参考答案:
S0h6J"x;~s6R Y5E0makefile:LUPA开源社区2U:N!Wu2m
hello:  hello.o msg.o   head.hLUPA开源社区~n:}4Z-M'WPduj
        gcc hello.c msg.c -o hello

l5t4Bx#Z BB_0 LUPA开源社区:n:@xc o Q iR

msg.o:  msg.c head.hLUPA开源社区X!n L[7c2n0b
        gcc -c msg.c

*^3OK{#r%tX^L6v0 LUPA开源社区egUS,?p-d%[b

hello.o:        hello.c
Rw;g)[\ G"A0        gcc -c hello.c

@FS|}p!E { X4kk0 LUPA开源社区;f4l4q,k2Hhn

chen:   chen.cLUPA开源社区1nyut)^0\
        gcc chen.c -o chen
Rje U5P0all:    hello chenLUPA开源社区Y?X&Da i%_#e

qK1wSD%GI0clean:LUPA开源社区g%s ?~ aVHn*C)D$C _
        rm hello chen *.o

&z#XsVa,e(_-Z I0

!g?3B H7W"SJp@0 LUPA开源社区'w8k0}/J*UU%m o

b@Y^:Zj/@0______________________________
^h.s-u M%e04)承上题,用autoconf制作可移值的自配制程序(configure,make,make install)

C A&C MV0

Iw2}'B"VC jo04.1)在根目录下新建devel目录,及子目录src,将以上源程序全部移入src目录下
l+B {?$V.m04.2)在hello.c中加入<config.h>LUPA开源社区T~[3Dvt
4.3)用autoscan生成configure.scanLUPA开源社区T*R|B~-Q ]3h!b
4.4)将configure.scan改名为configure.ac
` wy U6G:y04.5)编辑configure.ac,将应用程序名定义为ckhitler,版本为1.0LUPA开源社区 Eg*[~r
4.6)编辑configure.ac,将automake定义的应用程序名为hello,版本为1.0LUPA开源社区 u G.t!x a`
4.7)编辑configure.ac,定义输出本目录下的makefile文件和src目录下的makefileLUPA开源社区)J4?a9g E$n8sP
4.8)用acloacl扩展宏,生成aclocal.m4  autom4te.cache
8^\ CWjVu$E04.9)用autoconf生成configureLUPA开源社区| mZ(?t ? |7w^3R
4.10)新建并编辑根目录下的Makefile.am文件,指定子目录src
,`? r2OS2DCW7AGJ04.11)新建并编辑子目录src下的Makefile.am文件,指定bin_PROGRAMS为hello chen,并为其逐个指定源文件LUPA开源社区1O juRb
4.12)用autoheader生成config.h.in
T,E;G/GKF} OY^a04.13)用automake生成install-sh   Makefile.in missing depcomp config.h src/Makefile.in
2R[`2N:PW!U.GrI2GY04.14)执行configure,make,make install检查结果LUPA开源社区$u#C b&ZE
4.15)执行hello chen查看执行结果LUPA开源社区qSAK!}7\a
4.16)执行make clean清除目标文件和生成的可执行程序LUPA开源社区_@M.fr [4r

S%b9u*P.NO XC7p0
o!OL!n g-|0参考答案:
z5XR6Yb&[j0make -p /devel/srcLUPA开源社区%n9q o(},iTX9W Q
cp *.c *.h /devel/srcLUPA开源社区i hV,_'t R*q
cd /devel
IF!r,M@{-S0autoscan
!A9JyU#@0mv configure.scan configure.ac
ez1}#sYE1{0vi configure.ac

FL/s$mz+a*m0 LUPA开源社区k\8^!R}lF ] [

修改前:LUPA开源社区^B&x5n/]K"jK
AC_PREREQ(2.61)LUPA开源社区4y QQ2j_8{$^E on
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
-GbZ!sY(G/m0AC_CONFIG_SRCDIR([src/hello.c])
+yC'j-@;}f0AC_CONFIG_HEADER([config.h])

|Qh5jG0O0 LUPA开源社区2W"Lb*s)G"ER$H

修改后:LUPA开源社区.tIL\#H
AC_PREREQ(2.61)LUPA开源社区o A6^L~W
AC_INIT(ckhitler,1.0)
TgYXf:JP0AM_INIT_AUTOMAKE(hello,1.0)
E-ZS;o~4U$ftl Q0AC_CONFIG_SRCDIR([src/hello.c])LUPA开源社区0Vqm$b4Lc8LVw
AC_CONFIG_HEADER([config.h])
k6l+H0s~s:eAX0AC_CONFIG_FILES([MakefileLUPA开源社区dV6tjiU,It
                src/Makefile])LUPA开源社区:aV C-fCv

LUPA开源社区u3oD E8kD)gp


%Q M1D_"I&W;vB)j.R0acloacl
!g;d\ Wz4R't0autoconfLUPA开源社区e S,lvm"`7gt

LUPA开源社区%G7}8W1bL


J!Q,r"W1x3Q RbI0vi Makefile.amLUPA开源社区z~)I7e1s8S9l R
SUBDIRS=srcLUPA开源社区H7g6sO*iJ

g#rQ4o,ok0LUPA开源社区SHwrmWE
cd srcLUPA开源社区8R9K"[6P m;~w7u L
vi Makefile.am
g ^qW [FE0bin_PROGRAMS=hello chen
| t;JpM v0D*v0hello_SOURCES=hello.c head.h msg.c
L1I8CYy}%i0chen_SOURCES=chen.cLUPA开源社区%@W;I4`%K3y.o"s:_

LUPA开源社区CdWq#a:R5Q


%Avd:K9XuiCL0autoheaderLUPA开源社区 B? v ]"c@ i"V O:Z!r0K
automake --foreign --add-missing --copy

-F u1r1G8]}!| ` s0 LUPA开源社区5v)w l8R(S

LUPA开源社区y] d yrg:oMx'`X
./configureLUPA开源社区+zs2Wl3w
./makeLUPA开源社区&cl/OL"I7E!u*M1[9Z
./make installLUPA开源社区(AX7e"nV;@5]|_pe2l1V

|`(gceK.t0helloLUPA开源社区.o,zk&g6l0u8Xkg&U%W
chen
,x^ A"NR0make cleanLUPA开源社区ht'Mg#R!~


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-10-11  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 19380
  • 日志数: 60
  • 建立时间: 2007-07-22
  • 更新时间: 2008-07-31

RSS订阅

Open Toolbar