本文由博主原创,转载请注明出处(保留此处和链接):
一日二十四挨踢(http://1024it.net/?p=241)
下载链接:http://www.apuebook.com/ 我这里下载2005版本
编译平台:ubuntu 12.04
把下载的 src.2e.tar.gz 复制到 ~/workspace/c_wspace/unix$ (这里改为你自己的工作目录),解压生成 apue.2e目录,进入后使用make linux 编译
遇到问题:
Q1:
robin@ubuntu:~/workspace/c_wspace/unix/apue.2e$ make linux for i in lib sockets advio call calld daemons datafiles db environ exercises file ipc ipp lock mycat open opend opend.fe open.fe proc pty sess signals std stdio streams termios threadctl threads; do \ (cd $i && make -f linux.mk) || exit 1; \ done make[1]: Entering directory `/media/2ndDisk/workspace/c_wspace/unix/apue.2e/lib' gcc -DLINUX -ansi -I/home/sar/apue.2e/include -Wall -D_GNU_SOURCE -c -o bufargs.o bufargs.c bufargs.c:1:18: fatal error: apue.h: No such file or directory compilation terminated. make[1]: *** [bufargs.o] Error 1 make[1]: Leaving directory `/media/2ndDisk/workspace/c_wspace/unix/apue.2e/lib' make: *** [linux] Error 1
A1:
6 #WKDIR=/home/sar/apue.2e 7 WKDIR=/home/robin/workspace/c_wspace/unix/apue.2e注释掉第6行的WKDIR,改成自己的路径: /home/robin/workspace/c_wspace/unix/apue.2e
Q2:
In file included from /usr/include/i386-linux-gnu/bits/time.h:86:0, from /usr/include/time.h:42, from /usr/include/pthread.h:26, from printd.c:11: /usr/include/i386-linux-gnu/bits/timex.h:31:7: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘.’ token make[2]: *** [printd.o] Error 1 make[2]: Leaving directory `/media/2ndDisk/workspace/c_wspace/unix/apue.2e/ipp' make[1]: *** [linux] Error 1 make[1]: Leaving directory `/media/2ndDisk/workspace/c_wspace/unix/apue.2e' make: *** [all] Error 2
A2:
解决方法见:解决方法
Q3:
gcc -DLINUX -ansi -I/home/robin/workspace/c_wspace/unix/apue.2e/include -Wall -pthread -D_GNU_SOURCE -c -o getenv1.o getenv1.c getenv1.c:4:20: error: ‘ARG_MAX’ undeclared here (not in a function) getenv1.c:4:13: warning: ‘envbuf’ defined but not used [-Wunused-variable] make[2]: *** [getenv1.o] Error 1 make[2]: Leaving directory `/media/2ndDisk/workspace/c_wspace/unix/apue.2e/threadctl' make[1]: *** [linux] Error 1 make[1]: Leaving directory `/media/2ndDisk/workspace/c_wspace/unix/apue.2e' make: *** [all] Error 2
A3:
robin@ubuntu:~/workspace/c_wspace/unix/apue.2e$ vim threadctl/getenv1.c添加头文件 #include "apue.h"
robin@ubuntu:~/workspace/c_wspace/unix/apue.2e$ vim include/apue.h添加宏定义 #define ARG_MAX 4096
robin@ubuntu:~/workspace/c_wspace/unix/apue.2e$ vim threadctl/getenv3.c
添加头文件 #include "apue.h"