<unix网络编程> 的环境配置

<unix网络编程> 的环境配置

 

首先在网上下载UNP的库文件,然后就可以安装学了。我的系统环境:

2.6.32-131.0.15.el6.i686 #1 SMP Sat Nov 12 17:30:50 CST 2011 i686 i686 i386 GNU/Linux

LSB Version:    :base-4.0-ia32:base-4.0-noarch:core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID:    CentOS
Description:    CentOS release 6.1 (Final)
Release:    6.1
Codename:    Final


一. 生成libunp.a静态库

    cd unpv3e        #源目录
 
    ./configure     # try to figure out all implementation differences  
                       生成config.h配置文件
 
    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             生成libunp.a

二. 复制配置文件(也可用其他方法)
    
    cp unp.h          /usr/local/include     //要该变root权限,unp.h在lib目录中
    cp unpthread.h  /usr/local/include  //线程的头文件
    cp config.h     /usr/local/include     //config.h在源目录中
    cp libunp.a     /usr/local/lib        //libunp.a在源目录中
    
三. 修改配置文件
    
    cd /usr/local/include
    vim unp.h    #include "../config.h" 改为 #include "config.h",unp.h和config.h是在一起的。

    修改三个文件的权限属主(chown,chgrp)等

    为了使用g++进行编译:
    将unp.h和unpthead.h内容放在extern “C”中间
    extern "C" {
    ...
    } /* extern "C" */

    为了可以调试打印在unp.h中添加:
    #ifdef DEBUG
    #define DPRINTF(fmt, ...)        printf(fmt, ##__VA_ARGS__), printf("\n"), fflush(NULL)    
    #else
    #define DPRINTF(fmt, ...)        ((void)0)
    #endif

四. 修改环境变量(已添加的可以不用了)
    
    vim .bash_profile
    PATH中添加/usr/local/include:/usr/local/lib

五. 验证
    
    cd 源目录/intro

    gcc byteorder.c -o byteorder -lunp
    ./byteorder
    i686-pc-linux-gnu: little-endian
    验证OK

注意: 我们自己写程序时,不能使用c99标准的内容(例如for(int i)), 否则会出现unp.h编译错误。
    




    

 

 

posted on 2014-07-24 23:07  hancmhi  阅读(694)  评论(0编辑  收藏  举报