1. Download source code in http://www.apuebook.com
2. View READ
root@ubuntu:/home/wl/mywork/apue.2e# cat -n README 1Read the file called DISCLAIMER. 2 3Some source changes needed to be made after the book went out for the first 4printing. I forgot to make corresponding changes in the source tree on the 5system used to develop the book. The changes are summarized below. 6 71. lib/recvfd.c and sockets/recvfd.c - needed sys/uio.h on Mac OS X 82. lib/sendfd.c and sockets/sendfd.c - needed sys/uio.h on Mac OS X 93. stdio/buf.c - added code for Mac OS X 104. threadctl/suspend.c - changed wait to waitloc to avoid symbol definition 11clash on Solaris 125. include/apue.h - FreeBSD compiles work better if we rely on the default 13system settings. Solaris needed a different XOPEN_SOURCE definition 14and also a CMSG_LEN definition. 15 16To build the source, edit the Make.defines.* file for your system and set 17WKDIR to the pathname of the tree containing the source code. Then just 18run "make". It should figure out the system type and build the source for 19that platform automatically. If you are running on a system other than 20FreeBSD, Linux, Mac OS X, or Solaris, you'll need to modify the makefiles 21to include the settings for your system. Also, you'll probably need to 22modify the source code to get it to build on a different operating system. 23The example source was compiled and tested using FreeBSD 5.2.1, Linux 2.4.22, 24Mac OS X 10.3, and Solaris 9. 25 26For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com. 27Please direct questions, suggestions, and bug reports to sar@apuebook.com. 28 29Steve Rago 30May 30, 2005root@ubuntu:/home/wl/mywork/apue.2e#
You can see 19 rows starting from row 3 ~~
3. Modify Make. defines. linux
# Common make definitions, customized for each platform# Definitions required in all program directories to compile and link# C programs using gcc.WKDIR=/home/wl/mywork/apue.2e#WKDIR=/home/sar/apue.2eCC=gccCOMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -cLINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDDIR) $(LDFLAGS)LDDIR=-L../libLDLIBS=../lib/libapue.a $(EXTRALIBS)CFLAGS=-DLINUX -ansi -I$(WKDIR)/include -Wall -D_GNU_SOURCE $(EXTRA)CPPFLAGS=-I/home/wl/mywork/apue.2e/include# Our library that almost every program needs.LIB=../libapue.a# Common temp files to delete from each directory.TEMPFILES=core core.* *.o temp.* *.out typescript*~
You only need to change the above text to your own path ~~~
4. copy the apue. h and error. c files to/usr/include.
5. Edit apue. h.
# Vi apue. h
In the last line # endif/* _ APUE_H */
Add a line # include "error. c ".
6. Compile the source file
(Take the source \ file directory as an example)
# Cd file
# Cp linux. mk Makefile
# Make
root@ubuntu:/home/wl/mywork/apue.2e/file# makegcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib access.c ../lib/libapue.a -o accessgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib cdpwd.c ../lib/libapue.a -o cdpwdgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib changemod.c ../lib/libapue.a -o changemodgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib devrdev.c ../lib/libapue.a -o devrdevgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib fileflags.c ../lib/libapue.a -o fileflagsgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib filetype.c ../lib/libapue.a -o filetypegcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib ftw4.c ../lib/libapue.a -o ftw4gcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib hello.c ../lib/libapue.a -o hellogcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib hole.c ../lib/libapue.a -o holegcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib longpath.c ../lib/libapue.a -o longpathgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib ls1.c ../lib/libapue.a -o ls1gcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib mycd.c ../lib/libapue.a -o mycdgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib seek.c ../lib/libapue.a -o seekgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib testerror.c ../lib/libapue.a -o testerrorgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib uidgid.c ../lib/libapue.a -o uidgidgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib umask.c ../lib/libapue.a -o umaskgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib unlink.c ../lib/libapue.a -o unlinkgcc -DLINUX -ansi -I/home/wl/mywork/apue.2e/include -Wall -D_GNU_SOURCE -I/home/wl/mywork/apue.2e/include -L../lib zap.c ../lib/libapue.a -o zaproot@ubuntu:/home/wl/mywork/apue.2e/file#
Compiled successfully