(1)下载源代码,可以去官网下载:http://apuebook.com/code3e.html
(2)解压缩源代码文件:tar -zxvf src.3e.tar.gz
(3) 安装静态链接库:sudo apt-get install libbsd-dev
(4) make
(5).在编译成功的基础上,我们进行安装apue.h文件及其对应的静态链接库libapue.a
sudo cp ./include/apue.h /usr/include/
sudo cp ./lib/libapue.a /usr/local/lib/
为什么要将libapue.a移到/usr/local/lib中呢?原因是libapue.a是apue.h头文件中包含的所有函数及宏定义的具体实现,是一个静态链接库。
(6)创建apueerror.h文件
/**************
*
*apueerror.h
*
*************/
#include <apue.h> #include <stdio.h> #include <errno.h> /* for definition of errno */ #include <stdarg.h> /* ISO C variable aruments */ static void err_doit(int, int, const char *, va_list); /* * Nonfatal error related to a system call. * Print a message and return. */ void err_ret(const char *fmt, ...) { va_list ap; va_start(ap, fmt); err_doit(1, errno, fmt, ap); va_end(ap); } /* * Fatal error related to a system call. * Print a message and terminate. */ void err_sys(const char *fmt, ...) { va_list ap; va_start(ap, fmt); err_doit(1, errno, fmt, ap); va_end(ap); exit(1); } /* * Fatal error unrelated to a system call. * Error code passed as explict parameter. * Print a message and terminate. */ void err_exit(int error, const char *fmt, ...) { va_list ap; va_start(ap, fmt); err_doit(1, error, fmt, ap); va_end(ap); exit(1); } /* * Fatal error related to a system call. * Print a message, dump core, and terminate. */ void err_dump(const char *fmt, ...) { va_list ap; va_start(ap, fmt); err_doit(1, errno, fmt, ap); va_end(ap); abort(); /* dump core and terminate */ exit(1); /* shouldn't get here