本文转载自:http://blog.csdn.net/hadas_wang/article/details/43203795

1. 下载代码:http://www.apuebook.com/code3e.html

2. 安装依赖库:sudo apt-get install libbsd-dev 

3. 进入下载目录make

4. 复制头文件和动态链接库

  1. sudo cp ./include/apue.h /usr/include/
  2. sudo cp ./lib/libapue.a /usr/local/lib/
  3. sudo cp ./lib/libapue.a /usr/lib/

5. 设置错误文件error.h

  1. #include "apue.h"
  2. #include <errno.h>      /* for definition of errno */
  3. #include <stdarg.h>     /* ISO C variable aruments */
  4. static void err_doit(int, int, const char *, va_list);
  5. /*
  6. * Nonfatal error related to a system call.
  7. * Print a message and return.
  8. */
  9. void err_ret(const char *fmt, ...)
  10. {
  11. va_list     ap;
  12. va_start(ap, fmt);
  13. err_doit(1, errno, fmt, ap);
  14. va_end(ap);
  15. }
  16. /*
  17. * Fatal error related to a system call.
  18. * Print a message and terminate.
  19. */
  20. void err_sys(const char *fmt, ...)
  21. {
  22. va_list     ap;
  23. va_start(ap, fmt);
  24. err_doit(1, errno, fmt, ap);
  25. va_end(ap);
  26. exit(1);
  27. }
  28. /*
  29. * Fatal error unrelated to a system call.
  30. * Error code passed as explict parameter.
  31. * Print a message and terminate.
  32. */
  33. void err_exit(int error, const char *fmt, ...)
  34. {
  35. va_list     ap;
  36. va_start(ap, fmt);
  37. err_doit(1, error, fmt, ap);
  38. va_end(ap);
  39. exit(1);
  40. }
  41. /*
  42. * Fatal error related to a system call.
  43. * Print a message, dump core, and terminate.
  44. */
  45. void err_dump(const char *fmt, ...)
  46. {
  47. va_list     ap;
  48. va_start(ap, fmt);
  49. err_doit(1, errno, fmt, ap);
  50. va_end(ap);
  51. abort();        /* dump core and terminate */
  52. exit(1);        /* shouldn't get here */
  53. }
  54. /*
  55. * Nonfatal error unrelated to a system call.
  56. * Print a message and return.
  57. */
  58. void err_msg(const char *fmt, ...)
  59. {
  60. va_list     ap;
  61. va_start(ap, fmt);
  62. err_doit(0, 0, fmt, ap);
  63. va_end(ap);
  64. }
  65. /*
  66. * Fatal error unrelated to a system call.
  67. * Print a message and terminate.
  68. */
  69. void err_quit(const char *fmt, ...)
  70. {
  71. va_list     ap;
  72. va_start(ap, fmt);
  73. err_doit(0, 0, fmt, ap);
  74. va_end(ap);
  75. exit(1);
  76. }
  77. /*
  78. * Print a message and return to caller.
  79. * Caller specifies "errnoflag".
  80. */
  81. static void err_doit(int errnoflag, int error, const char *fmt, va_list ap)
  82. {
  83. char    buf[MAXLINE];
  84. vsnprintf(buf, MAXLINE, fmt, ap);
  85. if (errnoflag)
  86. snprintf(buf+strlen(buf), MAXLINE-strlen(buf), ": %s",
  87. strerror(error));
  88. strcat(buf, "\n");
  89. fflush(stdout);     /* in case stdout and stderr are the same */
  90. fputs(buf, stderr);
  91. fflush(NULL);       /* flushes all stdio output streams */
  92. }

6. 注销,重启

7. 代码文件

    1. #include "apue.h"
    2. #include "error.h"

Linux - Unix环境高级编程(第三版) 源代码编译(即头文件apue.h如何使用问题)【转】的更多相关文章

  1. Linux - Unix环境高级编程(第三版) 代码编译

    Unix环境高级编程(第三版) 代码编译 本文地址:http://blog.csdn.net/caroline_wendy 时间:2014.10.2 1. 下载代码:http://www.apuebo ...

  2. 【转】apue《UNIX环境高级编程第三版》第一章答案详解

    原文网址:http://blog.csdn.net/hubbybob1/article/details/40859835 大家好,从这周开始学习apue<UNIX环境高级编程第三版>,在此 ...

  3. Unix环境高级编程第三版中实例代码如何在自己的linux上运行的问题

    学习Linux已经有2个月了,最近被期末考试把进度耽误了,前几天把Unix环境高级编程看了两章,感觉对Linux的整体有了一些思路,今天尝试着对第一章涉及到的一个简单的交互式shell编译运行一下,结 ...

  4. APUE(unix环境高级编程)第三版---first day---部署书中实例的运行环境(apue.h)

    操作环境:RHEL7.0 部署apue.h实例运行环境 1.下载头文件src.3e.tar.gz 2.解压 tar zxvf src.3e.tar.gz 3.创建普通用户(我仿照书上创建的sar用户) ...

  5. 《UNIX环境高级编程第三版》apue.h等源码文件的编译安装

    操作系统:Ubuntu 12/14 1.下载书中的源代码:点击下载 2.编译 tar -zxvf *.tar.gz cd ./apue.3e make 报错: can,t find -lbsd 解决办 ...

  6. 《UNIX环境高级编程(第3版)》

    <UNIX环境高级编程(第3版)> 基本信息 原书名:Advanced Programming in the UNIX Environment (3rd Edition) (Addison ...

  7. unix环境高级编程第三章笔记

    文件描述符 1.文件描述符的概念 对于内核而言,所有打开的文件都会用一个文件描述符来引用,打开或和创建一个新文件的时候,内核会给进程返回一个文件描述符,而当使用read write时,可以使用这个文件 ...

  8. UNIX环境高级编程-第三章习题

    1,当读写磁盘文件时,read,write等函数确实是不带缓冲机制的吗?请说明原因. 答:所有磁盘I/O都要经过内核的块缓存区(即内核的缓冲区高速缓存).唯一例外的是对原始磁盘设备的I/O,但是我们不 ...

  9. 《UNIX环境高级编程 第2版》读书笔记

    CH1-2:基础知识.标准化 1 文件和目录 文件名:不能含/(分隔路径)和null(终止路径),255字符. 目录处理:opendir() readdir() closedir() 更改工作目录:c ...

随机推荐

  1. 洛谷—— P1440 求m区间内的最小值

    https://www.luogu.org/problemnew/show/P1440 题目描述 一个含有n项的数列(n<=2000000),求出每一项前的m个数到它这个区间内的最小值.若前面的 ...

  2. 缓存区溢出漏洞工具Doona

    缓存区溢出漏洞工具Doona   Doona是缓存区溢出漏洞工具BED的分支.它在BED的基础上,增加了更多插件,如nttp.proxy.rtsp.tftp等.同时,它对各个插件扩充了攻击载荷,这里也 ...

  3. HTTP状态码之200和304

    HTTP状态码之200和304   HTTP状态码(HTTP Status Code)是一种表示网页服务器响应状态的三位数字编码.通过这些数字,可以简化状态的表达.状态码有几十种,其中首位数字为1-5 ...

  4. Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  5. hadoop之hdfs------------------FileSystem及其源码分析

    FileSystem及其源码分析 FileSystem这个抽象类提供了丰富的方法用于对文件系统的操作,包括上传.下载.删除.创建等.这里多说的文件系统通常指的是HDFS(DistributedFile ...

  6. python设置utf-8为默认编码

    当使用Python编程时,编码问题一直很让人头疼,程序中经常会碰到如下错误提示: UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in ...

  7. jmeter的master、slave模型启动方法

    机器A为master:机器B为slave:可以一个master挂多个slave,方法就是-R参数后面跟一个逗号分割的IP列表 slave启动命令:./jmeter-server -Djava.rmi. ...

  8. LINUX下目标文件的BSS段、数据段、代码段

    http://blog.chinaunix.net/uid-27018250-id-3867588.html bss 未初始化的全局数据 data 已经初始化的全局数据 text 代码段,机器指令 r ...

  9. 解决MySQL出现大量unauthenticated user的问题

    近期OJ及相关的站点打开异常的慢,简直崩溃,一直没找着原因. 进入数据库server.进到mysql里,用show processlist命令查看一下,发现有非常多的unauthenticated u ...

  10. 前端学习——使用Ajax方式POST JSON数据包

    0.前言     本文解释怎样使用Jquery中的ajax方法传递JSON数据包,传递的方法使用POST(当然PUT又有时也是一个不错的选择).POST JSON数据包相比标准的POST格式可读性更好 ...