Linux網路編程(1):如何使用"unp.h"__html5

來源:互聯網
上載者:User

俗話說萬事開頭難,學習新知識也是如此,當我們下定決心要實現UNP中的例子時,發現卻無法將程式部署上去,這種感覺是不是很令人沮喪。本文就是用來給我自己這種linux菜鳥掃盲用的。


首先,UNP的源碼連結為 點擊開啟連結,下載完成後使用tar -zxvf命令進行解壓。

$ tar -zxvf unpv13e.tar.gz
解壓完成後,進入該目錄。

$ cd unpv13e
對於初學者,一看到軟體包裡這麼多的檔案,肯定會一頭霧水,這尼瑪都是用來幹啥的。不急,第一件事情就是去讀一下README。

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.1If all that works, you're all set to start compiling individual programs.Notice that all the source code assumes tabs every 4 columns, not 8.

第一步當然是./configure來檢查系統檔案了,等等。這怎麼這麼像用源碼安裝檔案,我們不是只用使用unp.h這個標頭檔麼。好吧,大牛的標頭檔怎麼能和菜鳥心目中簡陋的標頭檔一樣呢。

然後按照README的步驟一步一步的來,我只編譯了lib下面的base庫,當make完成之後,我們會發現make完成後提示

ranlib ../libunp.a

libunp.a?這是啥玩意,對,這個是靜態連結檔案。這時候有人肯定會疑問:靜態連結是用來幹啥的。這就複雜了,給大家個提示,百度”從代碼到可執行檔的過程“,”動態連結與靜態連結的區別“。接下來,進入advio檔案夾,嘗試著像readme所說的,make daytimetcpcli,我們會發現make的過程如下:

gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli daytimetcpcli.o ../libunp.a -lpthread

聰明如你立馬就從這個命令裡面想到了怎麼樣在自己建立的檔案夾裡使用gcc編譯unp裡面的例子了吧。

gcc -o daytimetcpcli(可執行檔) daytimetcpcli.c(C源檔案) /usr/lib/libunp.a(我自己的libunp.a的存放位置),再依據config.h和unp.h的具體位置,去編輯unp.h的#include ”../config.h",至此我開心地敲開了Unix網路編程的大門。




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.