UNIX網路程式設計之環境配置

2021-06-27 02:06:20 字數 2920 閱讀 6682

開始學習《unix網路程式設計》,輸入第乙個程式後,遇到各種錯誤,先將解決方案記錄如下。

mkdir /home/yourname/download   %建立存放壓縮檔案的目錄

tar -xzvf unpv13e.tar.gz                  %解壓

ls -al                                                %檢視該目錄下的檔案

cd   unpv13e                                   %進入unpv13e

cat readme                                   %檢視readme檔案,其中有具體的安裝資訊,按照操作即可

quick and dirty

***************

execute the following from the src/ directory:

./configure    # try to figure out all implementation differences

cd lib         # build the basic library that all programs need

make           # use "gmake" everywhere on bsd/os systems

cd ../libfree  # continue building the basic library

make

cd ../libroute # only if your system supports 4.4bsd style routing sockets

make           # only if your system supports 4.4bsd style routing sockets

cd ../libxti   # only if your system supports xti

make           # only if your system supports xti

cd ../intro    # build and test a basic client program

make daytimetcpcli

./daytimetcpcli 127.0.0.1

if all that works, you're all set to start compiling individual programs.

然後,複製unp.h和config.h到/usr/include

cp libunp.a /usr/lib

cp libunp.a /usr/lib64/

cd /lib

cp unp.h /usr/include

cp config.h /usr/include

最後,修改unp.h中的#include "../config.h"為#include "./config.h"。

以上是第乙個錯誤,下面的錯誤是:

undefined reference to 'err_quit'

undefined reference to 'err_sys'

這也是由於,意思是未定義的宣告,也就是說這些函式沒有實現,這時候在網上找的自定義錯誤處理函式myerr.h

#include "apue.h"

#include /* for definition of errno */

#include /* 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, ...)

/** fatal error related to a system call.

* print a message and terminate.

*/void

err_sys(const char *fmt, ...)

/** 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, ...)

/** fatal error related to a system call.

* print a message, dump core, and terminate.

*/void

err_dump(const char *fmt, ...)

/** nonfatal error unrelated to a system call.

* print a message and return.

*/void

err_msg(const char *fmt, ...)

/** fatal error unrelated to a system call.

* print a message and terminate.

*/void

err_quit(const char *fmt, ...)

/** print a message and return to caller.

* caller specifies "errnoflag".

*/static void

err_doit(int errnoflag, int error, const char *fmt, va_list ap)

UNIX 網路程式設計環境配置

在ubuntu中配置這本書的環境 第2步 通過終端,cd進入上面的壓縮包所在資料夾 然後執行 tar zxf unpv13e.tar.gz 第3步 安裝編譯器 sudo apt get install build essential第4步 進入unpv13e目錄 configure cd lib m...

unix環境程式設計之函式

man 3 strtok man 3 strtok r printf 3 linux programmer s manual printf 3 name printf,fprintf,sprintf,snprintf,vprintf,vfprintf,vsprintf,vsnprintf forma...

UNIX網路程式設計之SO REUSEADDR關鍵字

1 一般來說 乙個埠釋放後會等待兩分鐘之後才能再被使用 so reuseaddr 是讓埠釋放後立即就可以被再次使用。so reuseaddr 用於對tcp 套接字處於 time wait 狀態下的 socket 才可以重複繫結使用。server 程式總是應該在呼叫 bind 之前設定 so reus...