UNIX網絡編程書中源代碼測試環境搭建 (centos中取時間問題)

今天使用centos搭建了unix網絡編程的第一個練習,不停出錯,找到了一些資料外加自己調試,現在記錄下來


一.我用的是unpv12e.tar,在51cto裏面搜索《unix網絡編程》上面有;

二.最好專門建立一個文件目錄,我的是在/tmp/c/UNIX/unpv12e  ->>建議閱讀下README文     件        

三.進入目錄,運行./configure

四.進入 cd /tmp/c/UNIX/unpv12e/lib  

                                                 make  //產生錯誤


   錯誤代碼爲:

  1. gcc -g -O2 -D_REENTRANT -Wall   -c -o connect_nonb.o connect_nonb.c  

  2. In file included from connect_nonb.c:1:  

  3. unp.h:114: error: redefinition of ‘struct in_pktinfo’  

  4. make: *** [connect_nonb.o] 錯誤 1


redefinition of ‘struct in_pktinfo’的解決方法如下:

結構in_pktinfo已經包含在標準頭文件bits/in.h中了, 它又通過 netinet/in.h 在unp.h中被包括進來. 只要將 unp.h 中的結構定義comment out註釋掉就行了.

註釋掉之後重新

make  生成了../libunp.a文件。


五.cd ../libfree

           make


六.cd ../libgai  

           make  

錯誤提示如下:

gcc -g -O2 -D_REENTRANT -Wall   -c -o getaddrinfo.o getaddrinfo.c  getaddrinfo.c: In function ‘getaddrinfo’:  getaddrinfo.c:58: error: ‘EAI_ADDRFAMILY’ undeclared (first use in this function)  getaddrinfo.c:58: error: (Each undeclared identifier is reported only once  getaddrinfo.c:58: error: for each function it appears in.)  getaddrinfo.c:116: error: ‘EAI_NODATA’ undeclared (first use in this function)  make: *** [getaddrinfo.o] 錯誤 1

解決方法如下:


回到unpv12e目錄:


cd ..  vim configure.in

找到下面一行註釋掉
LIBGAI_OBJS="getaddrinfo.o getnameinfo.o freeaddrinfo.o gai_strerror.o"
然後用下面的代碼代替註釋掉的那行

LIBGAI_OBJS=if test "$ac_cv_func_getaddrinfo" = no ; thenLIBGAI_OBJS="$LIBGAI_OBJS getaddrinfo.o"fiif test "$ac_cv_func_getnameinfo" = no ; thenLIBGAI_OBJS="$LIBGAI_OBJS getnameinfo.o"fiif test "$ac_cv_func_freeaddrinfo" = no ; thenLIBGAI_OBJS="$LIBGAI_OBJS freeaddrinfo.o"fiif test "$ac_cv_func_gai_strerror" = no ; thenLIBGAI_OBJS="$LIBGAI_OBJS gai_strerror.o"fi

autoconf  ./configure  

gedit Make.defines  

在文件末尾加上下面這句:
CFLAGS = -g -O2 -D_REENTRANT -Wall -D_GNU_SOURCE

注意:使用x86_64架構的CPU,make時出現如下提示:

checking build system type... Invalid configuration `x86_64-pc-linux-gnuoldld': machine `x86_64-pc' not recognized
configure: error: /bin/sh ./config.sub x86_64-pc-linux-gnuoldld failed


命令如下:vim /tmp/c/UNIX/unpv12e/config.sub  在其中找到

# Recognize the basic CPU types with company name.
       vax-* | tahoe-* | i[3456]86-* | x86_64-* | i860-* | m68k-* | m68000-* | m88k-*

將紅色字段插入以上位置就可進行編譯了


七.將生成的文件複製到以下目錄:

[root@localhost unpv12e]# cp libunp.a /usr/lib
[root@localhost unpv12e]# cp libunp.a /usr/lib64
[root@localhost unpv12e]# vim lib/unp.h
[root@localhost unpv12e]# cp lib/unp.h /usr/include/
[root@localhost unpv12e]# cp config.h /usr/include/


八.編譯,運行,結果

     [root@localhost intro]#  gcc daytimetcpcli.c -o daytimetcpcli -lunp

     [root@localhost intro]# ./daytimetcpcli 127.0.0.1
Mon Aug 12 19:48:23 2013

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章