Chinaunix首页 | 论坛 | 博客
  • 博客访问: 941217
  • 博文数量: 403
  • 博客积分: 27
  • 博客等级: 民兵
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-25 22:20
文章分类

全部博文(403)

文章存档

2016年(3)

2015年(16)

2014年(163)

2013年(222)

分类: LINUX

2014-09-11 10:08:39

实验环境:centos7 gnome桌面版
1.安装编译器gcc,同时会自动安装依赖库。如未自动安装,需要手动安装。
  1. $sudo yum install gcc
2.下载apue.2e源码,并解压主目录~/
    
3.修改apue.2e源码下的环境变量设置文件Make.defines.linux
  1. $cd ~/apue.2e
  2. $pwd
  3.     yourdir
  4. $vim Make.defines.linux
  5.     WKDIR=yourdir
4.修改apue.2e/std下文件linux.mk
  1. $cd ~/apue.2e/std
  2. $vim linux.mk
  3. :%s/nawk/awk/g   //将所有nawk替换为awk
5.把apue.2e/include下作者自己定义的头文件apue.h放入系统头文库 /usr/include
  1. $cd ~/apue.2e/include
  2. $sudo cp apue.h /usr/include
6.在系统头文库 /usr/include中新建作者定义的出错处理函数,参考apue(2e)附录B
  1. $cd /usr/include
  2. $vim myerr.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
  10. err_ret(const char *fmt, ...)
  11. {
  12. va_list ap;
  13. va_start(ap, fmt);
  14. err_doit(1, errno, fmt, ap);
  15. va_end(ap);
  16. }
  17. /*
  18. * Fatal error related to a system call.
  19. * Print a message and terminate.
  20. */
  21. void
  22. err_sys(const char *fmt, ...)
  23. {
  24. va_list ap;
  25. va_start(ap, fmt);
  26. err_doit(1, errno, fmt, ap);
  27. va_end(ap);
  28. exit(1);
  29. }
  30. /*
  31. * Fatal error unrelated to a system call.
  32. * Error code passed as explict parameter.
  33. * Print a message and terminate.
  34. */
  35. void
  36. err_exit(int error, const char *fmt, ...)
  37. {
  38. va_list ap;
  39. va_start(ap, fmt);
  40. err_doit(1, error, fmt, ap);
  41. va_end(ap);
  42. exit(1);
  43. }
  44. /*
  45. * Fatal error related to a system call.
  46. * Print a message, dump core, and terminate.
  47. */
  48. void
  49. err_dump(const char *fmt, ...)
  50. {
  51. va_list ap;
  52. va_start(ap, fmt);
  53. err_doit(1, errno, fmt, ap);
  54. va_end(ap);
  55. abort(); /* dump core and terminate */
  56. exit(1); /* shouldn't get here */
  57. }
  58. /*
  59. * Nonfatal error unrelated to a system call.
  60. * Print a message and return.
  61. */
  62. void
  63. err_msg(const char *fmt, ...)
  64. {
  65. va_list ap;
  66. va_start(ap, fmt);
  67. err_doit(0, 0, fmt, ap);
  68. va_end(ap);
  69. }
  70. /*
  71. * Fatal error unrelated to a system call.
  72. * Print a message and terminate.
  73. */
  74. void
  75. err_quit(const char *fmt, ...)
  76. {
  77. va_list ap;
  78. va_start(ap, fmt);
  79. err_doit(0, 0, fmt, ap);
  80. va_end(ap);
  81. exit(1);
  82. }
  83. /*
  84. * Print a message and return to caller.
  85. * Caller specifies "errnoflag".
  86. */
  87. static void
  88. err_doit(int errnoflag, int error, const char *fmt, va_list ap)
  89. {
  90. char buf[MAXLINE] ;
  91. vsnprintf(buf, MAXLINE, fmt, ap);
  92. if (errnoflag)
  93. snprintf(buf+strlen(buf), MAXLINE-strlen(buf), ": %s",
  94. strerror(error));
  95. strcat(buf, " ");
  96. fflush(stdout); /* in case stdout and stderr are the same */
  97. fputs(buf, stderr);
  98. fflush(NULL); /* flushes all stdio output streams */
  99. }
7.在源码文件中编译所有文件
  1. $cd ~/apue.2e
  2. $make
8.编译报错
(1)如果出现stropts.h缺失的情况,则下载
,解压
    cp ./glibc-2.11/streams/stropts.h /usr/include
    cp ./glibc-2.11/bits/stropts.h /usr/include/bits
    cp ./glibc-2.11/sysdeps/x86_64/bits/xtitypes.h /usr/include/bits

(2)如果在编译时提示ARG_MAX未定义,可以修改如下:
    在apue.2e/include/apue.h中添加一行:
    #define ARG_MAX 4096
    打开apue.2e/threadctl/getenv1.c 和apue.2e/threadctl/getenv3.c,添加一行:
    #include "apue.h"
 (3)如果在编译时提示ipp.h error  expected 各种符号,因为ipp.h中的status与/usr/include/sysdeps/x86_64/timex.h中的status冲突了
    
把ipp.h中的宏定义#define status ... 改为#define Status,并在使用该定义的文件printd.c中将hp->status改为hp->Status


阅读(1306) | 评论(0) | 转发(0) |
0

上一篇:电影收藏

下一篇:定时器的算法分析

给主人留下些什么吧!~~