美文网首页
UNIX网络编程卷2 源码编译篇

UNIX网络编程卷2 源码编译篇

作者: Hope_加贝 | 来源:发表于2018-09-12 15:47 被阅读3次

    W. Richard Stevens的主页
    源代码下载>> ~/Downloads/unpv22e.tar.gz;

    1 tar -xzfv unpv22e.tar.gz
    2 cd unpv22e
    3 ./configure
    4 cd lib
    5 make
    

    make编译失败,因为需要对两个文件修改,unpv22e/config.h和unpv22e/wrapunix.c。

    vi   config.h  
    
    /*注释掉这三行*/
    // #define uint8_t unsigned char /* <sys/types.h> */  
    // #define uint16_t unsigned short /* <sys/types.h> */  
    // #define uint32_t unsigned int /* <sys/types.h> */ 
    
    /*添加MSG_R和MSG_W定义*/
    typedef unsigned long ulong_t;  
    #define MSG_R 0400  
    #define MSG_W 0200 
    
    添加_GNU_SOURCE定义
    vi config.h  
    #define _GNU_SOURCE 
    
    
    vi   lib/wrapunix.c
    
    /*编译warpunix.c,使用mkstemp函数替换mktemp函数*/
    
    void  
    Mktemp(char *template)  
    {  
         if (mkstemp(template) == NULL || template[0] == 0)  
             err_quit("mktemp error");  
     }
    

    再次执行make命令,会在unp22e目录下生成静态库文件libunpipc.a和在lib目录下生成目标文件*.o。
     将config.h和pipe目录下的unpipc.h 复制到/usr/include/目录下,并修改unpipc.h下面的#include "../config.h" 为 #include "config.h".(备注:由于考虑到UNIX网络编程卷1也把config.h拷贝到/usr/include目录中,所以需要把卷2的config.h改为其他名字,例如ipcconfig.h。同时也需要修改/pipe/unpipc.h文件中"./ipcconfig.h")。

     1 cd unp22e
     2 mv config.h ipcconfig.h
     3 
     4 vi pipe/unpipc.h
     5 /*unpipc.h修改内容*/
     6 #include "./ipconfig.h"
     7 
     8 /*复制libunpipc.a ipcconfig.h unpipc.h*/
     9 sudo cp ipcconfig.h pipe/unpipc.h  /usr/include
    10 sudo cp libunpipc.a  /usr/lib
    

    一切准备工作就绪,那就让我们来编译书本中的第一个例子mainpipe.c

    1 cd pipe
    2 
    3 gcc mainpipe.c server.c client.c -lunpipc -o mainpipe.out
    

    还是报错。搜索google加上-lpthread

     1 gcc mainpipe.c server.c client.c -lunpipc  -lpthread -lrt -o mainpipe.out
     2 
     3 ./mainnpipe.out
    

    完成~

    相关文章

      网友评论

          本文标题:UNIX网络编程卷2 源码编译篇

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