記錄一次搭建unix網絡編程環境過程中遇到的問題和總結
計算機環境虛擬機 linuxmint-18-xfce-64bit
1.打開unix網絡編程.iso
把目錄下的文件復制到某一目錄,修改權限,可命令可鼠標操作。
2.
s@ss-Linux ~/unix/unpv13e $ sudo su [sudo] s 的密碼: ss-Linux unpv13e # ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for gcc... gcc checking for C compiler default output... configure: error: C compiler cannot create executables See `config.log' for more details.
很明顯在檢測環境時gcc無法生成可執行文件。
於是我又執行了一次configure,還是同樣的結果。
我查看了一下config.log也看不大明白。
上網翻博客。。。也沒查到相關內容。
3.突發奇想,編譯器出現問題,不如換個編譯器。
s-Linux unpv13e # apt-get install g++ 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關系樹 正在讀取狀態信息... 完成 將會同時安裝下列軟件: binutils cpp-5 g++-5 gcc-5 gcc-5-base gcc-5-base:i386 libasan2 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libgcc-5-dev libgfortran3 libgomp1 libitm1 liblsan0 libmpx0 libquadmath0 libstdc++-5-dev libstdc++6:i386 libstdc++6 libtsan0 libubsan0 建議安裝: binutils-doc gcc-5-locales g++-multilib g++-5-multilib gcc-5-doc libstdc++6-5-dbg gcc-5-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan2-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx0-dbg libquadmath0-dbg glibc-doc libstdc++-5-doc 下列【新】軟件包將被安裝: g++ g++-5 libc-dev-bin libc6-dev libstdc++-5-dev 下列軟件包將被升級: binutils cpp-5 gcc-5 gcc-5-base gcc-5-base:i386 libasan2 libatomic1 libcc1-0 libcilkrts5 libgcc-5-dev libgfortran3 libgomp1 libitm1 liblsan0 libmpx0 libquadmath0 libstdc++6:i386 libstdc++6 libtsan0 libubsan0 。。。。。。。。(略)
上面可以看到gcc等,希望有用。
4.再次執行configure

ss-Linux unpv13e # ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for gcc... gcc checking for C compiler default output... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ANSI C... none needed checking for ranlib... ranlib checking for pthread_create in -lpthread... yes checking for t_open in -lnsl... no checking for library containing socket... none required checking for /usr/local/bind/lib/libbind.a... no checking for /root/libbind.a... no checking for /root/libresolv.a... no checking for res_init in -lresolv... no checking for t_open in -lxti... no checking for /root/libunp.a... no checking for /root/libunpxti.a... no checking how to run the C preprocessor... gcc -E checking for egrep... grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/socket.h... yes checking for sys/time.h... yes checking for time.h... yes checking for netinet/in.h... yes checking for arpa/inet.h... yes checking for errno.h... yes checking for fcntl.h... yes checking for netdb.h... yes checking for signal.h... yes checking for stdio.h... yes checking for stdlib.h... yes checking for string.h... yes checking for sys/stat.h... yes checking for sys/uio.h... yes checking for unistd.h... yes checking for sys/wait.h... yes checking for sys/un.h... yes checking for sys/param.h... yes checking for sys/select.h... yes checking for sys/sysctl.h... yes checking for poll.h... yes checking for sys/event.h... no checking for strings.h... yes checking for sys/ioctl.h... yes checking for sys/filio.h... no checking for sys/sockio.h... no checking for pthread.h... yes checking for net/if_dl.h... no checking for xti.h... no checking for xti_inet.h... no checking for netconfig.h... no checking for netdir.h... no checking for stropts.h... yes checking whether time.h and sys/time.h may both be included... yes checking if uint8_t defined... yes checking if int16_t defined... yes checking if uint16_t defined... yes checking if int32_t defined... yes checking if uint32_t defined... yes checking if size_t defined... yes checking if ssize_t defined... yes checking if socklen_t defined... yes checking if sa_family_t defined... yes checking if t_scalar_t defined... yes checking if t_uscalar_t defined... yes checking for struct sockaddr.sa_len... no checking for struct sockaddr_storage... yes checking for struct sockaddr_storage.ss_family... yes checking for struct msghdr.msg_control... yes checking for struct ifreq.ifr_mtu... yes checking for getaddrinfo function prototype in netdb.h... yes checking for getnameinfo function prototype in netdb.h... yes checking for gethostname function prototype in unistd.h... yes checking for getrusage function prototype in sys/resource.h... yes checking for hstrerror function prototype in netdb.h... yes checking for if_nametoindex function prototype in net/if.h... yes checking for inet_aton function prototype in arpa/inet.h... yes checking for inet_pton function prototype in arpa/inet.h... yes checking for pselect function prototype in sys/select.h... yes checking for snprintf function prototype in stdio.h... yes checking for sockatmark function prototype in sys/socket.h... yes checking for struct addrinfo... yes checking for struct if_nameindex... yes checking for struct sockaddr_dl... no checking for struct timespec... yes checking for /dev/tcp... no checking for /dev/xti/tcp... no checking for /dev/streams/xtiso/tcp... no checking for bzero... yes checking for getaddrinfo... yes checking for gethostname... yes checking for gethostbyname2... yes checking for gethostbyname_r... yes checking for getnameinfo... yes checking for hstrerror... yes checking for if_nametoindex... yes checking for inet_aton... yes checking for inet_pton... yes checking for inet6_rth_init... yes checking for kqueue... no checking for kevent... no checking for mkstemp... yes checking for poll... yes checking for pselect... yes checking for snprintf... yes checking for sockatmark... yes checking for vsnprintf... yes checking for IPv4 support... yes checking for IPv6 support... yes checking for Unix domain sockets... yes checking for multicast support... yes checking for -I/root/doc/unp2ev1/src/include... no configure: creating ./config.status config.status: creating Makefile config.status: creating Make.defines config.status: creating config.h
5.明顯通過檢測生成了
Makefile
Make.defines
config.h
6.根據readme的指示,編譯庫文件

ss-Linux unpv13e # cd lib ss-Linux lib # make gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o connect_nonb.o connect_nonb.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o connect_timeo.o connect_timeo.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daemon_inetd.o daemon_inetd.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daemon_init.o daemon_init.c daemon_init.c: In function ‘daemon_init’: daemon_init.c:34:2: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result] chdir("/"); /* change working directory */ ^ gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o dg_cli.o dg_cli.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o dg_echo.o dg_echo.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o error.o error.c error.c: In function ‘err_doit’: error.c:102:17: warning: format not a string literal and no format arguments [-Wformat-security] syslog(level, buf); ^ gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o get_ifi_info.o get_ifi_info.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o gf_time.o gf_time.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o host_serv.o host_serv.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o family_to_level.o family_to_level.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_leave.o mcast_leave.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_join.o mcast_join.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_get_if.o mcast_get_if.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_get_loop.o mcast_get_loop.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_get_ttl.o mcast_get_ttl.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_set_if.o mcast_set_if.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_set_loop.o mcast_set_loop.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o mcast_set_ttl.o mcast_set_ttl.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o my_addrs.o my_addrs.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o read_fd.o read_fd.c read_fd.c: In function ‘read_fd’: read_fd.c:45:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *recvfd = *((int *) CMSG_DATA(cmptr)); ^ gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o readline.o readline.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o readn.o readn.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o readable_timeo.o readable_timeo.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o rtt.o rtt.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o signal.o signal.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o signal_intr.o signal_intr.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_bind_wild.o sock_bind_wild.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_cmp_addr.o sock_cmp_addr.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_cmp_port.o sock_cmp_port.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_ntop.o sock_ntop.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_ntop_host.o sock_ntop_host.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_get_port.o sock_get_port.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_set_addr.o sock_set_addr.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_set_port.o sock_set_port.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sock_set_wild.o sock_set_wild.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o sockfd_to_family.o sockfd_to_family.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o str_cli.o str_cli.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o str_echo.o str_echo.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o tcp_connect.o tcp_connect.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o tcp_listen.o tcp_listen.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o tv_sub.o tv_sub.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o udp_client.o udp_client.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o udp_connect.o udp_connect.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o udp_server.o udp_server.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wraplib.o wraplib.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrapsock.o wrapsock.c wrapsock.c: In function ‘Inet6_rth_space’: wrapsock.c:81:8: warning: implicit declaration of function ‘inet6_rth_space’ [-Wimplicit-function-declaration] ret = inet6_rth_space(type, segments); ^ wrapsock.c: In function ‘Inet6_rth_init’: wrapsock.c:93:8: warning: implicit declaration of function ‘inet6_rth_init’ [-Wimplicit-function-declaration] ret = inet6_rth_init(rthbuf, rthlen, type, segments); ^ wrapsock.c:93:6: warning: assignment makes pointer from integer without a cast [-Wint-conversion] ret = inet6_rth_init(rthbuf, rthlen, type, segments); ^ wrapsock.c: In function ‘Inet6_rth_add’: wrapsock.c:103:6: warning: implicit declaration of function ‘inet6_rth_add’ [-Wimplicit-function-declaration] if (inet6_rth_add(rthbuf, addr) < 0) ^ wrapsock.c: In function ‘Inet6_rth_reverse’: wrapsock.c:110:6: warning: implicit declaration of function ‘inet6_rth_reverse’ [-Wimplicit-function-declaration] if (inet6_rth_reverse(in, out) < 0) ^ wrapsock.c: In function ‘Inet6_rth_segments’: wrapsock.c:119:8: warning: implicit declaration of function ‘inet6_rth_segments’ [-Wimplicit-function-declaration] ret = inet6_rth_segments(rthbuf); ^ wrapsock.c: In function ‘Inet6_rth_getaddr’: wrapsock.c:131:8: warning: implicit declaration of function ‘inet6_rth_getaddr’ [-Wimplicit-function-declaration] ret = inet6_rth_getaddr(rthbuf, idx); ^ wrapsock.c:131:6: warning: assignment makes pointer from integer without a cast [-Wint-conversion] ret = inet6_rth_getaddr(rthbuf, idx); ^ gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrapstdio.o wrapstdio.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrappthread.o wrappthread.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o wrapunix.o wrapunix.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o write_fd.o write_fd.c write_fd.c: In function ‘write_fd’: write_fd.c:24:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *((int *) CMSG_DATA(cmptr)) = sendfd; ^ gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o writen.o writen.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o writable_timeo.o writable_timeo.c ar rv ../libunp.a connect_nonb.o connect_timeo.o daemon_inetd.o daemon_init.o dg_cli.o dg_echo.o error.o get_ifi_info.o gf_time.o host_serv.o family_to_level.o mcast_leave.o mcast_join.o mcast_get_if.o mcast_get_loop.o mcast_get_ttl.o mcast_set_if.o mcast_set_loop.o mcast_set_ttl.o my_addrs.o read_fd.o readline.o readn.o readable_timeo.o rtt.o signal.o signal_intr.o sock_bind_wild.o sock_cmp_addr.o sock_cmp_port.o sock_ntop.o sock_ntop_host.o sock_get_port.o sock_set_addr.o sock_set_port.o sock_set_wild.o sockfd_to_family.o str_cli.o str_echo.o tcp_connect.o tcp_listen.o tv_sub.o udp_client.o udp_connect.o udp_server.o wraplib.o wrapsock.o wrapstdio.o wrappthread.o wrapunix.o write_fd.o writen.o writable_timeo.o ar: 正在創建 ../libunp.a a - connect_nonb.o a - connect_timeo.o a - daemon_inetd.o a - daemon_init.o a - dg_cli.o a - dg_echo.o a - error.o a - get_ifi_info.o a - gf_time.o a - host_serv.o a - family_to_level.o a - mcast_leave.o a - mcast_join.o a - mcast_get_if.o a - mcast_get_loop.o a - mcast_get_ttl.o a - mcast_set_if.o a - mcast_set_loop.o a - mcast_set_ttl.o a - my_addrs.o a - read_fd.o a - readline.o a - readn.o a - readable_timeo.o a - rtt.o a - signal.o a - signal_intr.o a - sock_bind_wild.o a - sock_cmp_addr.o a - sock_cmp_port.o a - sock_ntop.o a - sock_ntop_host.o a - sock_get_port.o a - sock_set_addr.o a - sock_set_port.o a - sock_set_wild.o a - sockfd_to_family.o a - str_cli.o a - str_echo.o a - tcp_connect.o a - tcp_listen.o a - tv_sub.o a - udp_client.o a - udp_connect.o a - udp_server.o a - wraplib.o a - wrapsock.o a - wrapstdio.o a - wrappthread.o a - wrapunix.o a - write_fd.o a - writen.o a - writable_timeo.o ranlib ../libunp.a
7.編譯庫文件
ss-Linux lib # cd ../libfree ss-Linux libfree # make gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o in_cksum.o in_cksum.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_ntop.o inet_ntop.c inet_ntop.c: In function ‘inet_ntop’: inet_ntop.c:60:9: error: argument ‘size’ doesn’t match prototype size_t size; ^ In file included from inet_ntop.c:27:0: /usr/include/arpa/inet.h:64:20: error: prototype declaration extern const char *inet_ntop (int __af, const void *__restrict __cp, ^ <builtin>: recipe for target 'inet_ntop.o' failed make: *** [inet_ntop.o] Error 1
錯誤原因可以看出是
類型不對。
通過搜索 可以知道
ANSCI創造了size_t數據類型,它用作malloc的唯一參數(待分配的字節數),或者作為read和write的第三個參數(待讀寫的字節數)。在32位系統中,size_t是一個32位值,但是64位系統中它必須是一個64位值,以便發揮更大尋址模型的優勢。這意味着64位系統中也許含有一個把size_t定義為unsigned long的typedef指令。聯網API存在如下問題:POSIX.1g的某些草案規定,存放套接字的地址結構大小的函數參數具有size_t的數據類型(如bind和connect的第三個參數)。某些XTI結構也含有數據類型為long的成員(如t_info和t_opthdr結構)。如果這些規定不加修改,當unix從ILP32模型轉為LP64模型時,size_t和long都將從32位變成64位值,這兩個列子實際上並不需要使用64的數據類型:套接字的地址結構的長度最多也就幾百個字節,給XTI的結構成員使用long數據類型是個錯誤。
處理這些情況的辦法是使用專門設計的數據類型。套接字API對套接字地址結構的長度使用socklen_t數據類型,XTI則使用t_scalar_t和t_uscalar_t數據類型。不把這些值由32位改為64位的理由是易於為那些已經在32位系統上編譯的應用程序提供在新的64位系統中的二進制代碼的兼容性
我的電腦是64位。
解決辦法
找到inet_ntop.c第61行 size_t size ->改成 socklen_t size)
8.重新編譯
ss-Linux libfree # make gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_ntop.o inet_ntop.c /usr/include/arpa/inet.h: In function ‘inet_ntop’: inet_ntop.c:152:23: warning: ‘best.len’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (best.base == -1 || cur.len > best.len) ^ inet_ntop.c:123:28: note: ‘best.len’ was declared here struct { int base, len; } best, cur; ^ gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o inet_pton.o inet_pton.c ar rv ../libunp.a in_cksum.o inet_ntop.o inet_pton.o a - in_cksum.o a - inet_ntop.o a - inet_pton.o ranlib ../libunp.a
9.路由套接字 庫
ss-Linux libfree # cd ../libroute ss-Linux libroute # make gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o get_rtaddrs.o get_rtaddrs.c In file included from get_rtaddrs.c:1:0: unproute.h:3:45: fatal error: net/if_dl.h: 沒有那個文件或目錄 compilation terminated. <builtin>: recipe for target 'get_rtaddrs.o' failed make: *** [get_rtaddrs.o] Error 1
又出錯了,
c - What package do i need to install for using routing sockets? - Stack Overflow
http://stackoverflow.com/questions/1520649/what-package-do-i-need-to-install-for-using-routing-sockets
Please note, you DO NOT need to make in that folder "libroute" See the Document: 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 Linux is not BSD style routing, just go to ../intro and build examples~!
好吧,編譯到此結束。
10.打開lib目錄
修改unp.h
#include "../config.h"
改成
#include "config.h"
11.返回unpv13e文件夾
ss-Linux unpv13e # cp config.h /usr/local/include ss-Linux unpv13e # cp lib/unp.h /usr/local/include ss-Linux unpv13e # sudo cp libunp.a /usr/local/lib ss-Linux unpv13e # cd intro
12.到此搭建完畢,測試一下
ss-Linux intro # gcc daytimetcpcli.c -o 獲取時間 /tmp/cciq4Jvt.o:在函數‘main’中: daytimetcpcli.c:(.text+0x3b):對‘err_quit’未定義的引用 daytimetcpcli.c:(.text+0x6d):對‘err_sys’未定義的引用 daytimetcpcli.c:(.text+0xe5):對‘err_quit’未定義的引用 daytimetcpcli.c:(.text+0x114):對‘err_sys’未定義的引用 daytimetcpcli.c:(.text+0x153):對‘err_sys’未定義的引用 daytimetcpcli.c:(.text+0x196):對‘err_sys’未定義的引用 collect2: error: ld returned 1 exit status
又錯。。。。。
按道理頭文件,庫文件都弄好了啊。......
有個makefile,make,make,make編譯成功。[上面的問題,第二天解決了,請翻到最后。初學者很無奈。。。。。。。
ss-Linux intro # make gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli.o daytimetcpcli.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli daytimetcpcli.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli1.o daytimetcpcli1.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli1 daytimetcpcli1.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli2.o daytimetcpcli2.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli2 daytimetcpcli2.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcli3.o daytimetcpcli3.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli3 daytimetcpcli3.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv.o daytimetcpsrv.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv daytimetcpsrv.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv1.o daytimetcpsrv1.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv1 daytimetcpsrv1.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv2.o daytimetcpsrv2.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv2 daytimetcpsrv2.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrv3.o daytimetcpsrv3.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv3 daytimetcpsrv3.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpcliv6.o daytimetcpcliv6.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcliv6 daytimetcpcliv6.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o daytimetcpsrvv6.o daytimetcpsrvv6.c gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrvv6 daytimetcpsrvv6.o ../libunp.a -lpthread gcc -I../lib -g -O2 -D_REENTRANT -Wall -c -o byteorder.o byteorder.c byteorder.c: In function ‘main’: byteorder.c:21:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=] printf("sizeof(short) = %d\n", sizeof(short)); ^ gcc -I../lib -g -O2 -D_REENTRANT -Wall -o byteorder byteorder.o ../libunp.a -lpthread
成功!
測試一下
ss-Linux intro # ./daytimetcpcli 127.0.0.1 connect error: Connection refused
又出錯。。。
繼續上搜索引擎
原來是由於某些原因daytime服務並沒有啟動,可能系統還沒有安裝這個服務。
13.安裝xinetd
ss-Linux intro # apt-get install xinetd
具體請百度,不作解釋。
14.啟用daytime服務
打開 /etc/xinetd.d/daytime 有2個文件修改
disable yes 改為 disable no
重啟服務
service xinetd restart
15.再次測試
ss-Linux intro # ./daytimetcpcli 127.0.0.1 13 AUG 2016 20:39:16 CST
成功!!!
12.1.關於單獨編譯daytimetcpcli.c出錯的原因
沒有指定需要鏈接的庫。
gcc -l參數是用來指定程序要鏈接的庫,-l緊接着就是庫名,那么庫名跟真正的庫文件名有什么關系呢?就拿數學庫來說,他的庫名是m,他的庫文件名是libm.so,容易看出,把庫文件名的頭lib和尾.so去掉就是庫名
解決加入libunp.a庫
ss-Linux intro # gcc daytimetcpcli.c -o 獲取時間 -lunp ss-Linux intro # ./獲取時間 127.0.0.1 14 AUG 2016 08:20:15 CST
感想:
1.花費了兩天時間終於粗略的把環境搭建好了,想深入學習,深刻感受到基礎知識的重要性。沒有系統學習過linux,make命令等等,非常吃力。遇到問題,都不知道如何搜索問題,只能把錯誤信息粘貼到搜索引擎上,盲目的搜索。
2.眼高手低
3.對於幫助文檔一定要好好看,不要什么一上來就去搜索引擎上去尋找答案。
4.第二次搭建環境了,第一次亂七八糟弄好也遇到很多問題沒解決,這一次基本上都解決了。以后應認真學習努力加油!
最后,寫的有些倉促,肯定存在一些細節錯誤或者沒寫出來,假如你看到了請指出來,有問題一起來討論。后續我會繼續修改文章的。
轉載請注明出處。謝謝。