apue源代码的使用与编译
- 格式:pdf
- 大小:39.98 KB
- 文档页数:1
apue源代码的使⽤与编译
原⽂⽹址:
编译源代码
1、从官⽹下载源代码
2、解压
3、默认解压后的源代码名称为:apue.2e,⾥⾯包含了所有的代码
4、修改⽬录,我的系统是ubuntu10.10,修改apue.2e下的Make.defines.linux
WKDIR=/home/sdoning/apue/apue.2e(主要是该路径)
5、在apue.2e⽬录下运⾏make命令
6、错误与解决
gcc -DLINUX -ansi -I/home/sdoning/apue/apue.2e/include -Wall -D_GNU_SOURCE -c -o getenv1.o getenv1.c
getenv1.c:4: error: ‘ARG_MAX’ undeclared here (not in a function)
make[2]: *** [getenv1.o] Error 1
make[2]: Leaving directory `/home/sdoning/apue/apue.2e/threadctl’
make[1]: *** [linux] Error 1
make[1]: Leaving directory `/home/sdoning/apue/apue.2e’
make: *** [all] Error 2
解决⽅法:
在apue.2e/include/apue.h中添加⼀⾏:#define ARG_MAX 4096
打开apue.2e/threadctl/getenv3.c(包括getenv1.c),添加⼀⾏:#include "apue.h"
7、再次编译即可。
使⽤源代码:
1、知道源代码的软连接与位置
sdoning@ubuntu:~/apue/apue.2e$ ll fig1.3
lrwxrwxrwx 1 sdoning sdoning 10 2010-11-27 07:27 fig1.3 -> file/ls1.c
2、进⼊file⽬录
sdoning@ubuntu:~/apue/apue.2e/file$ ls
access devrdev.c ftw4.c longpath.c seek.c umask.c
access.c fileflags hello ls1 solaris.mk unlink
cdpwd fileflags.c hello.c ls1.c testerror unlink.c
cdpwd.c filetype hole macos.mk testerror.c zap
changemod filetype.c hole.c mycd uidgid zap.c
changemod.c freebsd.mk linux.mk mycd.c uidgid.c
devrdev ftw4 longpath seek umask
3、运⾏
./ls1 /home
..
sdoning
.