《UNP》中源代码的编译和使用

http://blog.chinaunix.net/uid-10780339-id-189358.html


分类: 网络相关 
最近看了下《UNIX网络编程》,就想把里面的源代码搞过来运行下。以前也搞过,不过老是忘记使用代码的步骤了,所以就记录下,防止每次还要弄半天。

从网上下载压缩包解压到自己设定的目录下面,我的是/home/**/myprogram/UNP/unpv13e/,里面有 
./ 
├── aclocal.m4 
├── advio 
├── bcast 
├── config.guess 
├── config.h 
├── config.h.in 
├── config.log 
├── config.status 
├── config.sub 
├── configure 
├── configure.in 
├── debug 
├── DISCLAIMER 
├── icmpd 
├── inetd 
├── install-sh 
├── intro 
├── ioctl 
├── ipopts 
├── key 
├── lib 
├── libfree 
├── libgai 
├── libroute 
├── libunp.a(就是为了生成这个文件) 
├── Make.defines 
├── Make.defines.in 
├── Makefile 
├── Makefile.in 
├── mcast 
├── mysdr 
├── names 
├── nonblock 
├── oob 
├── ping 
├── README 
├── route 
├── rtt 
├── sctp 
├── select 
├── server 
├── sigio 
├── sock 
├── sockopt 
├── sparc64-unknown-freebsd5.1 
├── ssntp 
├── streams 
├── tcpcliserv 
├── test 
├── threads 
├── traceroute 
├── udpcksum 
├── udpcliserv 
├── unixdomain 
├── unpv13e 
└── VERSION

这么多的东西,呵呵!!,当然我们不能忘记了README这个助手 
QUICK AND DIRTY 
===============

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

If all that works, you 
其实需要执行的就是前三步,其实就是为了生成libunp.a。复制这个静态库到/usr/lib/和/usr/lib64/中,因为后来编译程序的话需要用到这个静态库。还得在环境变量中将这两个路径加上。

接下来的是头文件unp.h的问题,这个文件在这个解压缩目录的lib文件夹中。

因为里面所有的文件都包含了#include“unp.h”这一句话,为了方便可以有两种方法: 
一: 
1.将lib下面的unp.h复制到/usr/include文件夹下面,并保证环境变量中有/usr/include; 
2.因为unp.h中有#include "../config.h",所以得把解压缩目录下面的config.h复制到/usr/include中,并将unp.h中的#include "../config.h"改成 #include "config.h"。 
3在unp.h中添加一行: 
#define MAX_LINE 2048

二: 
1.将Lib文件夹下面的unp.h移到unpv13e中, 
2.参照上面的第二条; 
3.参照上面的第三条; 
4.以后在子文件夹里面编译程序,把#include"unp.h"改为#include"../unp.h"

做完上面,我们就可以编译单个程序了,比如intro/byteorder.c。

root@**-desktop:/home/**/myprogram/UNP/unpv13e/intro# gcc -W -o byteorder byteorder.c -lunp 
root@**-desktop:/home/**/myprogram/UNP/unpv13e/intro# ./byteorder 
i686-pc-linux-gnu: little-endian

呵呵,就这样!



转者注:我的机子是Linux version 2.6.32-24-generic (buildd@rothera) (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 

                  Ubuntu 10.04.1 LTS

         这个并没有usr/lib64/文件夹,所以并没有拷贝到这个下面。同时在环境变量是加入到我个人用户“/home/myname”下的.bashrc文件中,这是用于单个用户的环境变量设置文件。大家可以参照一下,如果有什么问题,欢迎留言讨论。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值