<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編譯錯誤。
?? ?
?? ?
?
?