现在的位置: 首页 > 综合 > 正文

编译APUE附带源码

2011年06月08日 ⁄ 综合 ⁄ 共 1658字 ⁄ 字号 评论关闭

编译APUE附带源码

之前写的关于创建静态库的方法直接使用书中代码的方法http://hi.baidu.com/logicbaby/blog/item/3dc21fdb4ce75b60d0164e4e.html

今天仔细看了下源码包文件夹下的README文件,才知道不用这么麻烦,那源码包是可以直接安装的,但是都是建立静态库的方法啦。

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.

1、从http://www.apuebook.com/下载Source Code

2、解压后看到文件夹下有好几个类似Make.defines.*的文件Make.defines.macos ,Make.defines.solaris
,Make.defines.linux,Make.defines.freebsd,如果不是FreeBSD, Linux ,Mac OS X , Solaris的就得自己配置了,如果是FreeBSD系统则修改Make.defines.freebsd,修改WKDIR为apue.2e所在的文件夹,比如我的为WKDIR=/home/clooo/apue.2e。

3、在apue.2e文件夹下直接运行make即可,其实通过Makefile发现,首先运行systype.sh判断系统的类别,然后再编译,将书中要用到的函数编译成一个静态库apue.2e/lib/libapue.a。

4、测试

clooo@~% uname -a
FreeBSD logicbaby.localdomain 6.3-RELEASE FreeBSD 6.3-RELEASE #0: Wed Jan 16 04:45:45 UTC 2008     root@dessler.cse.buffalo.edu:/usr/obj/usr/src/sys/SMP i386

clooo@~/apue.2e% cp fig1.3 fig1.3.c
将fig1.3.c第一行改为
#include "include/apue.h"
clooo@~/apue.2e% cc fig1.3.c lib/libapue.a
clooo@~/apue.2e% ./a.out ~
.
..
.cshrc
.login
.mail_aliases
.login_conf
.rhosts
.mailrc
.profile
.shrc
apue.2e
src.tar.gz
.history
clooo@~/apue.2e%

后记:

1、我同时使用FreeBSD 6.3和Debian 4 , Debian下的方法相同,只是在第一步的时候修改的是Make.defines.linux文件中的WKDIR

2、apue.2e在FreeBSD 7.0下编译出错,提示pracct.c中的acct结构体未定义,查看/usr/include/sys
下的acct.h发现有acctv1和acctv2,将acct改为acctv2即可。

抱歉!评论已关闭.