APUE随书源代码编译

from:http://www.360doc.com/showWeb/0/0/308952.aspx

最近在看apue的第二版,刚才在Linux下把随书的源代码编译了一遍,还是稍微花了点时间,作为备忘把编译过程记录下来
随书的源代码可从 www.apuebook.com上获得,下载后的解压得到名为apue.2e的目录,在我的系统中该目录的完整路径为/home/se/apue.2e
接着首先是要阅读/home/se/apue.2e/README,这是由apue第二版的作者Steve Rago写的如何编译随书代码的基本指导以及部分自本书第一版以来的更改,主要内容如下:
Some source changes needed to be made after the book went out for the first
printing.  I forgot to make corresponding changes in the source tree on the
system used to develop the book.  The changes are summarized below.
1. lib/recvfd.c and sockets/recvfd.c - needed sys/uio.h on Mac OS X
2. lib/sendfd.c and sockets/sendfd.c - needed sys/uio.h on Mac OS X
3. stdio/buf.c - added code for Mac OS X
4. threadctl/suspend.c - changed wait to waitloc to avoid symbol definition
 clash on Solaris
5. include/apue.h - FreeBSD compiles work better if we rely on the default
 system settings.  Solaris needed a different XOPEN_SOURCE definition
 and also a CMSG_LEN definition.
To build the source, edit the Make.defines.* file for your system and set
WKDIR to the pathname of the tree containing the source code.  Then just
run "make".  It should figure out the system type and build the source for
that platform automatically.  If you are running on a system other than
FreeBSD, Linux, Mac OS X, or Solaris, you'll need to modify the makefiles
to include the settings for your system.  Also, you'll probably need to
modify the source code to get it to build on a different operating system.
The example source was compiled and tested using FreeBSD 5.2.1, Linux 2.4.22,
Mac OS X 10.3, and Solaris 9.
For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com.
Please direct questions, suggestions, and bug reports to sar@apuebook.com.
 
基本内容就是你用的系统如果是FreeBSD,Linux,Mac OS X或是Solaris,那么你只要修改相应的Make.defines.*文件(即如果你使用的是Linux,那么你需要修改 Make.defines.linux文件的内容),将其中的设置改为你自己系统的设置然后在apue.2e目录下运行make就ok了.所有的代码都在 FreeBSD 5.2.1,Linux 2.4.22,Mac OS X 10.3,Solaris 9上编译通过.
 
总的来说要编译成功是很简单的,但总会因为平台的不同会出现一些错误,这时你就要根据自己系统的配置情况来进行修改了
1.首先粗略的看了一下makefile的内容,make首先会执行脚本文件systype.sh,判断所用系统的类型,然后根据该类型选择对 应的Make.defines文件.这里所要做的就是给systype.sh添加执行权限,chmod u+x systype.sh
2.因为我用的是Linux,所以先看Make.defines.linux,需要修改的地方是WKDIR= /home/sar/apue.2e,把WKDIR改为你自己的工作目录,在我这就是改为WKDIR=/home/se/apue.2e,这个路径在编译 时寻找"apue.h"头文件时使用.
3.然后我尝试性的运行了一次make,果然有问题,在进入std目录后报错了,说找不到nawk命令,nawk是new awk,而我的系统上只有awk,这时你有两种选择,可以在运行make之前执行alias nawk='awk',这样本质上是给awk取了个叫nawk的别名,实际上运行的还是awk,另一种方法就是修改 WKDIR/std/linux.mk,把第10行和15行中的nawk都改为awk,至于什么是awk和nawk,以及它们的使用方法可以参考我之前收 藏的一篇文章 http://www.360doc.com/showWeb/0/0/308938.aspx
在这里,awk用来分别从makeconf.awk和makeopt.awk生成conf.c和options.c源文件,注意,在修改了linux.mk或是添加了alias之后要先把之前make失败时生成的conf.c和options.c删除,否则会报错
4.进行了上述的修改后,回到WKDIR,运行make,ok,没有报错,编译成功了
之后,如果你要利用apue的lib,编译运行自己的代码,必须在编译时加上-I/home/se/apue.2e/include选项,在连 接时加上-L/home/se/apue.2e/lib source.c /home/se/apue.2e/lib/libapue.a选项,这样你就可以利用apue提供的想err_sys等函数了^_^
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值