《UNIX环境高级编程》第二版源码在Ubuntu下的编译

1.在http://www.apuebook.com下载源代码

2. 查看READ

root@ubuntu:/home/wl/mywork/apue.2e# cat -n README 
     1	Read the file called DISCLAIMER.
     2	
     3	Some source changes needed to be made after the book went out for the first
     4	printing.  I forgot to make corresponding changes in the source tree on the
     5	system used to develop the book.  The changes are summarized below.
     6	
     7	1. lib/recvfd.c and sockets/recvfd.c - needed sys/uio.h on Mac OS X
     8	2. lib/sendfd.c and sockets/sendfd.c - needed sys/uio.h on Mac OS X
     9	3. stdio/buf.c - added code for Mac OS X
    10	4. threadctl/suspend.c - changed wait to waitloc to avoid symbol definition
    11		clash on Solaris
    12	5. include/apue.h - FreeBSD compiles work better if we rely on the default
    13		system settings.  Solaris needed a different XOPEN_SOURCE definition
    14		and also a CMSG_LEN definition.
    15	
    16	To build the source, edit the Make.defines.* file for your system and set
    17	WKDIR to the pathname of the tree containing the source code.  Then just
    18	run "make".  It should figure out the system type and build the source for
    19	that platform automatically.  If you are running on a system other than
    20	FreeBSD, Linux, Mac OS X, or Solaris, you'll need to modify the makefiles
    21	to include the settings for your system.  Also, you'll probably need to
    22	modify the source code to get it to build on a different operating system.
    23	The example source was compiled and tested using FreeBSD 5.2.1, Linux 2.4.22,
    24	Mac OS X 10.3, and Solaris 9.
    25	
    26	For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com.
    27	Please direct questions, suggestions, and bug reports to [email protected].
    28	
    29	Steve Rago
    30	May 30, 2005
root@ubuntu:/home/wl/mywork/apue.2e# 

从第16行开始看到19行就可以了~~

3. 修改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.2e
CC=gcc
COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c
LINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDDIR) $(LDFLAGS)
LDDIR=-L../lib
LDLIBS=../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*
~                                                     
各位只需要修改上面大字部分改为自己的路径就可以了~~~

4. 将apue.h和error.c两个文件copy到/usr/include下

5. 编辑apue.h
#vi apue.h
在最后一行 #endif /* _APUE_H */

前面添加一行 #include "error.c"。

6. 编译源文件

(以source\file目录为例)
#cd file
#cp linux.mk Makefile
#make


root@ubuntu:/home/wl/mywork/apue.2e/file# make
gcc -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 access
gcc -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 cdpwd
gcc -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 changemod
gcc -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 devrdev
gcc -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 fileflags
gcc -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 filetype
gcc -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 ftw4
gcc -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 hello
gcc -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 hole
gcc -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 longpath
gcc -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 ls1
gcc -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 mycd
gcc -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 seek
gcc -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 testerror
gcc -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 uidgid
gcc -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 umask
gcc -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 unlink
gcc -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 zap
root@ubuntu:/home/wl/mywork/apue.2e/file# 
编译成功


------------------------------------------------------------enjoy-------------------------------------------------------------------------------------

-----------------------------------------------------------the end-----------------------------------------------------------------------------------

你可能感兴趣的:(编程,源码,linux,unix,ubuntu)