|
1.編譯《UNP》 http://www./unpv13e.tar.gz 我們首先產(chǎn)生一個目錄,以后自己的代碼就敲在這個目錄里。 mkdir /home/hehe/study/unp 仍然是下載到/home/hehe/download/,解壓縮,進入目錄 cd /home/hehe/download/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 ======================================== 這里只編譯lib下的文件,這樣可以產(chǎn)生libunp.a,復(fù)制這個靜態(tài)庫到/usr/lib/和/usr/lib64/ 如果提示: unp.h:139: error: conflicting types for ‘socklen_t’ /usr/include/bits/socket.h:35: error: previous declaration of ‘socklen_t’ was here 需要注釋掉當(dāng)前目錄中unp.h的第139行。 復(fù)制libunp.a到系統(tǒng)目錄: root@dan-laptop:/home/hehe/download/unpv13e/lib# cp ../libunp.a /usr/lib root@dan-laptop:/home/hehe/download/unpv13e/lib# cp ../libunp.a /usr/lib64/ 2.使用unp.h和libunp.a 如果直接復(fù)制unpv13e/lib/unp.h和config.h到/usr/include,那么在別的目錄編譯書上代碼時,很可會得到類似下面的錯誤: In file included from daytimetcpsrv1.c:1: /usr/include/unp.h:227: error: redefinition of ‘struct sockaddr_storage’ In file included from daytimetcpsrv1.c:1: /usr/include/unp.h:249:30: error: ../lib/addrinfo.h: No such file or directory /usr/include/unp.h:263: error: redefinition of ‘struct timespec’ /usr/include/unp.h:363: error: conflicting types for ‘gai_strerror’ /usr/include/netdb.h:647: error: previous declaration of ‘gai_strerror’ was here /usr/include/unp.h:367: error: conflicting types for ‘getnameinfo’ /usr/include/netdb.h:653: error: previous declaration of ‘getnameinfo’ was here /usr/include/unp.h:371: error: conflicting types for ‘gethostname’ /usr/include/unistd.h:857: error: previous declaration of ‘gethostname’ was here /usr/include/unp.h:387: error: conflicting types for ‘inet_ntop’ /usr/include/arpa/inet.h:65: error: previous declaration of ‘inet_ntop’ was here /usr/include/unp.h:395: error: conflicting types for ‘pselect’ /usr/include/sys/select.h:121: error: previous declaration of ‘pselect’ was here daytimetcpsrv1.c: In function ‘main’: daytimetcpsrv1.c:9: error: ‘MAX_LINE’ undeclared (first use in this function) daytimetcpsrv1.c:9: error: (Each undeclared identifier is reported only once daytimetcpsrv1.c:9: error: for each function it appears in.) dan@dan-laptop:~/study/unp/4$ rm -f /usr/include/unp.h 這是因為unp.h包含config.h使用的是#include "../config.h",而此時unp.h和config.h的位置關(guān)系發(fā)生了變化,只需改為#include "./config.h"即可 |
|
|