码迷,mamicode.com
首页 > 其他好文 > 详细

unix网络编程 代碼編譯

时间:2018-02-09 22:18:41      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:post   tran   127.0.0.1   clu   follow   building   ***   only   for   

查看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.1
yuanoung@ThinkPad-X260:~/Projects/unixNetwork/lib$ cd ../libfree
yuanoung@ThinkPad-X260:~/Projects/unixNetwork/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
yuanoung@ThinkPad-X260:~/Projects/unixNetwork/libfree$ vim inet_ntop.c 
--〉将第60行的 size_t size 改成 socklen_t size;  再次make,有警告,但是可以忽略。

將文件拷貝到指定的目錄:

yuanoung@ThinkPad-X260:~/Projects/unixNetwork$ sudo cp libunp.a /usr/lib
yuanoung@ThinkPad-X260:~/Projects/unixNetwork$ sudo cp lib/unp.h /usr/include
yuanoung@ThinkPad-X260:~/Projects/unixNetwork$ sudo cp config.h /usr/include
yuanoung@ThinkPad-X260:~/Projects/unixNetwork$ vim lib/unp.h   # 将#include "../config.h" 改成 #include "config.h"

對代碼進行編譯:

yuanoung@ThinkPad-X260:~/Projects/unixNetwork/intro$ gcc daytimetcpcli.c -o cli -lunp
yuanoung@ThinkPad-X260:~/Projects/unixNetwork/intro$ gcc daytimetcpsrv.c -o srv -lunp

運行第一個例子:

yuanoung@ThinkPad-X260:~/Projects/unixNetwork/intro$ sudo ./srv


yuanoung@ThinkPad-X260:~/Projects/unixNetwork/intro$ ./cli 127.0.0.1
Fri Feb  9 20:09:46 2018
yuanoung@ThinkPad-X260:~/Projects/unixNetwork/intro$ ./cli 127.0.0.1
Fri Feb  9 20:09:47 2018

unix网络编程 代碼編譯

标签:post   tran   127.0.0.1   clu   follow   building   ***   only   for   

原文地址:https://www.cnblogs.com/yuanoung/p/8436720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!