天天看點

Linux - Unix環境進階程式設計(第三版) 源代碼編譯(即頭檔案apue.h如何使用問題)【轉】...

本文轉載自: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. 複制頭檔案和動态連結庫

[plain]  view plain copy

Linux - Unix環境進階程式設計(第三版) 源代碼編譯(即頭檔案apue.h如何使用問題)【轉】...
Linux - Unix環境進階程式設計(第三版) 源代碼編譯(即頭檔案apue.h如何使用問題)【轉】...
  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

[cpp]  view plain copy

Linux - Unix環境進階程式設計(第三版) 源代碼編譯(即頭檔案apue.h如何使用問題)【轉】...
Linux - Unix環境進階程式設計(第三版) 源代碼編譯(即頭檔案apue.h如何使用問題)【轉】...
  1. #include "apue.h"  
  2. #include <errno.h>        
  3. #include <stdarg.h>       
  4. static void err_doit(int, int, const char *, va_list);  
  5. void err_ret(const char *fmt, ...)  
  6. {  
  7.     va_list     ap;  
  8.     va_start(ap, fmt);  
  9.     err_doit(1, errno, fmt, ap);  
  10.     va_end(ap);  
  11. }  
  12. void err_sys(const char *fmt, ...)  
  13. {  
  14.     va_list     ap;  
  15.     va_start(ap, fmt);  
  16.     err_doit(1, errno, fmt, ap);  
  17.     va_end(ap);  
  18.     exit(1);  
  19. }  
  20. void err_exit(int error, const char *fmt, ...)  
  21. {  
  22.     va_list     ap;  
  23.     va_start(ap, fmt);  
  24.     err_doit(1, error, fmt, ap);  
  25.     va_end(ap);  
  26.     exit(1);  
  27. }  
  28. void err_dump(const char *fmt, ...)  
  29. {  
  30.     va_list     ap;  
  31.     va_start(ap, fmt);  
  32.     err_doit(1, errno, fmt, ap);  
  33.     va_end(ap);  
  34.     abort();          
  35.     exit(1);          
  36. }  
  37. void err_msg(const char *fmt, ...)  
  38. {  
  39.     va_list     ap;  
  40.     va_start(ap, fmt);  
  41.     err_doit(0, 0, fmt, ap);  
  42.     va_end(ap);  
  43. }  
  44. void err_quit(const char *fmt, ...)  
  45. {  
  46.     va_list     ap;  
  47.     va_start(ap, fmt);  
  48.     err_doit(0, 0, fmt, ap);  
  49.     va_end(ap);  
  50.     exit(1);  
  51. }  
  52. static void err_doit(int errnoflag, int error, const char *fmt, va_list ap)  
  53. {  
  54.     char    buf[MAXLINE];  
  55.    vsnprintf(buf, MAXLINE, fmt, ap);  
  56.    if (errnoflag)  
  57.        snprintf(buf+strlen(buf), MAXLINE-strlen(buf), ": %s",  
  58.          strerror(error));  
  59.    strcat(buf, "\n");  
  60.    fflush(stdout);       
  61.    fputs(buf, stderr);  
  62.    fflush(NULL);         
  63. }  

6. 登出,重新開機

7. 代碼檔案

[cpp]  view plain copy

Linux - Unix環境進階程式設計(第三版) 源代碼編譯(即頭檔案apue.h如何使用問題)【轉】...
Linux - Unix環境進階程式設計(第三版) 源代碼編譯(即頭檔案apue.h如何使用問題)【轉】...
    1. #include "apue.h"  
    2. #include "error.h"