美文网首页
《UNIX网络编程》: source code 编译

《UNIX网络编程》: source code 编译

作者: my_passion | 来源:发表于2021-06-22 23:14 被阅读0次

查 Ubuntu 版本

$ cat /proc/version
Linux version 5.8.0-53-generic (buildd@lcy01-amd64-012) 
(gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 
GNU ld (GNU Binutils for Ubuntu) 2.34) 
#60~20.04.1-Ubuntu SMP 

开始编译

cd unpv13e/

按 README 指引进行

1.
./configure    # try to figure out all implementation differences
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 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 sys/event.h... no
2.
cd lib         # build the basic library that all programs need
make           # use "gmake" everywhere on BSD/OS systems
$ make
gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o connect_nonb.o connect_nonb.c
In file included from unp.h:48,
                 from connect_nonb.c:1:
/usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp]
   21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed."
      |  ^~~~~~~
gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o connect_timeo.o connect_timeo.c
In file included from unp.h:48,
                 from connect_timeo.c:2:
/usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp]
// ...
   21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed."
      |  ^~~~~~~
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: creating ../libunp.a
a - connect_nonb.o
a - connect_timeo.o
a - daemon_inetd.o
a - daemon_init.o
a - mcast_set_if.o
a - mcast_set_loop.o
a - mcast_set_ttl.o
//...
ranlib ../libunp.a
3.
cd ../intro    # build and test a basic client program
make daytimetcpcli

Connection refused 错误

/lib$ cd ../intro
/intro$ make daytimetcpcli
gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o daytimetcpcli.o daytimetcpcli.c
In file included from ../lib/unp.h:48,
                 from daytimetcpcli.c:1:
/usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp]
   21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed."
      |  ^~~~~~~
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpcli daytimetcpcli.o ../libunp.a -lpthread
/intro$ ./daytimetcpcli 127.0.0.1
connect error: Connection refused

4. 再开个窗口, 编译运行同一目录下 server 程序

make daytimetcpsrv
/intro$ make daytimetcpsrv
gcc -I../lib -g -O2 -D_REENTRANT -Wall   -c -o daytimetcpsrv.o daytimetcpsrv.c
In file included from ../lib/unp.h:48,
                 from daytimetcpsrv.c:1:
/usr/include/x86_64-linux-gnu/sys/sysctl.h:21:2: warning: #warning "The <sys/sysctl.h> header is deprecated and will be removed." [-Wcpp]
   21 | #warning "The <sys/sysctl.h> header is deprecated and will be removed."
      |  ^~~~~~~
gcc -I../lib -g -O2 -D_REENTRANT -Wall -o daytimetcpsrv daytimetcpsrv.o ../libunp.a -lpthread
intro$ sudo ./daytimetcpsrv
[sudo] password for mypassion: 
Sorry, try again.
[sudo] password for mypassion: 

不用 sudo 也可以

5. 在 第 1 个 窗口 再 运行 刚才的 client 程序

$ ./daytimetcpcli 127.0.0.1
image.png

success

相关文章

网友评论

      本文标题:《UNIX网络编程》: source code 编译

      本文链接:https://www.haomeiwen.com/subject/dgedyltx.html