My Environment.
===========================================================
shunwang@shunwang-desktop:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic
shunwang@shunwang-desktop:~$ uname -a
Linux shunwang-desktop 2.6.31-20-generic #57-Ubuntu SMP Mon Feb 8 09:05:19 UTC 2010 i686 GNU/Linux
===========================================================
Get the source code, from http://www.apuebook.com/
1. Modify apue.2e/Make.defines.linux
WKDIR=/home/shunwang/shawn_file/myfiles/my_study/kernel/APUE_source_code/apue/apue.2e
#WKDIR=/home/sar/apue.2e
2. ARG_MAX undeclared.
Error description.
$ make
...
make[2]: Entering directory `/home/shunwang/shawn_file/myfiles/my_study/kernel/APUE_source_code/apue/apue.2e/threadctl'
gcc -DLINUX -ansi -I/home/shunwang/shawn_file/myfiles/my_study/kernel/APUE_source_code/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/shunwang/shawn_file/myfiles/my_study/kernel/APUE_source_code/apue/apue.2e/threadctl'
make[1]: *** [linux] Error 1
make[1]: Leaving directory `/home/shunwang/shawn_file/myfiles/my_study/kernel/APUE_source_code/apue/apue.2e'
make: *** [all] Error 2
Solution:
在apue.2e/include/apue.h中添加一行:
#define ARG_MAX 4096
打开apue.2e/threadctl/getenv3.c,添加一行:
#include "apue.h"
再运行make, 编译通过。
3. 使用第一章的例子fig1.3
# ll fig1.3
lrwxrwxrwx 1 shunwang shunwang 10 2010-07-08 10:30 fig1.3 -> file/ls1.c
#ls file
access cdpwd.c devrdev fileflags.c freebsd.mk hello hole.c longpath.c macos.mk seek testerror uidgid.c unlink zap.c
access.c changemod devrdev.c filetype ftw4 hello.c linux.mk ls1 mycd seek.c testerror.c umask unlink.c
cdpwd changemod.c fileflags filetype.c ftw4.c hole longpath ls1.c mycd.c solaris.mk uidgid umask.c zap
# ./file/ls1 /home/
shunwang
..
lost+found
.
Error on Fedora 13 and the solution:
refer to: http://blog.chinaunix.net/u3/96584/showart_2121016.html
apue2配书源码在Fedora-12下的编译
1 获得源码
从apue的官方网站http://www.apuebook.com/下载源码。
2 WKDIR
编辑源码解压生成的apue.2e文件夹下的Make.defines.linux
修改WKDIR=/home/sar/apue.2e为你的apue.2e目录,
比如我的apue源码解压在主目录下,那我就改为:
WKDIR=/home/tgl/apue.2e
3 nawk
然后进入apue.2e/std 目录,编辑linux.mk。修改里面所有的nawk为awk。
4 stropts.h
如果出现stropts.h找不到的情况,则下载glibc-2.11,解压缩
cp ./glibc-2.11/streams/stropts.h /usr/include
cp ./glibc-2.11/bits/stropts.h /usr/include/bits
cp ./glibc-2.11/sysdeps/x86_64/bits/xtitypes.h /usr/include/bits
5 ARG_MAX
在我的机器上编译时,提示ARG_MAX未定义,可以这么修改。
在apue.2e/include/apue.h中添加一行:
#define ARG_MAX 4096
打开apue.2e/threadctl/getenv1.c 和apue.2e/threadctl/getenv3.c,添加一行:
#include "apue.h"
评论