1. 下载源码,W. Richard Stevens的主页:http://www.kohala.com/start/
wget http://www.kohala.com/start/unpv22e/unpv22e.tar.gz -P /usr/local/src 
2. 解压
tar xvf /usr/local/src/unpv22e.tar.gz -C /root/bin 
3. 编译库文件
cd /root/bin/unpv22e/  
./configure 
编辑生成config.h文件,注释以下几行
vi config.h  
56 // #define uint8_t unsigned char  
57 // #define uint16_t unsigned short  
58 // #define uint32_t unsigned int  
添加MSG_R和MSG_W定义
vi config.h  
66 // add by jcq  
67 typedef unsigned long ulong_t;  
68 #define MSG_R 0400  
69 #define MSG_W 0200 
添加_GNU_SOURCE定义
vi config.h  
#define _GNU_SOURCE 
修改warpunix.c中的MKtemp函数,使用mkstemp函数替换mktemp函数
cd lib  
181 void  
182 Mktemp(char *template)  
183 {  
184 if (mkstemp(template) == NULL || template[0] == 0)  
185 err_quit("mktemp error");  
186 } 
编译生成libunpipc.a
cd lib  
make
 
将生成的libunpipc.a复制到/usr/lib中。
[root@localhost myunp2]# vim ftok.c
[root@localhost myunp2]# gcc -o ftok ftok.c
/tmp/ccxRydhw.o: In function `main':
ftok.c:(.text+0x18): undefined reference to `err_quit'
ftok.c:(.text+0x30): undefined reference to `Stat'
ftok.c:(.text+0x48): undefined reference to `Ftok'
collect2: 错误:ld 返回
[root@localhost myunp2]# gcc -o ftok ftok.c -lunpipc
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_open':
wrapunix.c:(.text+0x4d8): undefined reference to `mq_open'
wrapunix.c:(.text+0x4f0): undefined reference to `mq_open'
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_close':
wrapunix.c:(.text+0x52b): undefined reference to `mq_close'
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_unlink':
wrapunix.c:(.text+0x55b): undefined reference to `mq_unlink'
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_send':
wrapunix.c:(.text+0x5a3): undefined reference to `mq_send'
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_receive':
wrapunix.c:(.text+0x5e3): undefined reference to `mq_receive'
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_notify':
wrapunix.c:(.text+0x623): undefined reference to `mq_notify'
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_getattr':
wrapunix.c:(.text+0x653): undefined reference to `mq_getattr'
/usr/lib/libunpipc.a(wrapunix.o): In function `Mq_setattr':
wrapunix.c:(.text+0x68b): undefined reference to `mq_setattr'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_open':
wrapunix.c:(.text+0x9c8): undefined reference to `sem_open'
wrapunix.c:(.text+0x9e0): undefined reference to `sem_open'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_close':
wrapunix.c:(.text+0xa1b): undefined reference to `sem_close'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_unlink':
wrapunix.c:(.text+0xa4b): undefined reference to `sem_unlink'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_init':
wrapunix.c:(.text+0xa8b): undefined reference to `sem_init'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_destroy':
wrapunix.c:(.text+0xabb): undefined reference to `sem_destroy'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_wait':
wrapunix.c:(.text+0xaeb): undefined reference to `sem_wait'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_trywait':
wrapunix.c:(.text+0xb1c): undefined reference to `sem_trywait'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_post':
wrapunix.c:(.text+0xb5b): undefined reference to `sem_post'
/usr/lib/libunpipc.a(wrapunix.o): In function `Sem_getvalue':
wrapunix.c:(.text+0xb93): undefined reference to `sem_getvalue'
/usr/lib/libunpipc.a(wrapunix.o): In function `Shm_open':
wrapunix.c:(.text+0xccc): undefined reference to `shm_open'
/usr/lib/libunpipc.a(wrapunix.o): In function `Shm_unlink':
wrapunix.c:(.text+0xd0b): undefined reference to `shm_unlink'
collect2: 错误:ld 返回
[root@localhost myunp2]# gcc -lrt -o ftok ftok.c -lunpipc
[root@localhost myunp2]# man mq_open
Cannot open the message catalog "man" for locale "zh_CN.UTF-8"
(NLSPATH="/usr/share/locale/%l/LC_MESSAGES/%N") Formatting page, please wait...

出现上面的错误,使用gcc 加选项-lrt解决。

错误:

[root@localhost myunp2]# gcc -lrt -o slot slot.c -lunpipc
slot.c: 在函数‘main’中:
slot.c::: 错误:‘IPC_PRIVATE’未声明(在此函数内第一次使用)
msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);
^
slot.c::: 附注:每个未声明的标识符在其出现的函数内只报告一次
In file included from slot.c:::
unpipc.h::: 错误:‘MSG_R’未声明(在此函数内第一次使用)
#define SVMSG_MODE (MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)
^
slot.c::: 附注:in expansion of macro ‘SVMSG_MODE’
msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);
^
unpipc.h::: 错误:‘MSG_W’未声明(在此函数内第一次使用)
#define SVMSG_MODE (MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)
^
slot.c::: 附注:in expansion of macro ‘SVMSG_MODE’
msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);
^
slot.c::: 错误:‘IPC_CREAT’未声明(在此函数内第一次使用)
msqid=Msgget(IPC_PRIVATE,SVMSG_MODE|IPC_CREAT);
^
slot.c::: 错误:‘IPC_RMID’未声明(在此函数内第一次使用)
Msgctl(msqid,IPC_RMID,NULL);

解决方法:

1.unpv22e里面的Make.defines 
修改 
#CFLAGS = -g -O2 -D_REENTRANT -Wall 
CFLAGS = -g -O2 -D_GNU_SOURCE -D__USE_GNU -D_REENTRANT -Wall

2 将unpv22e中的unpipc.h拷贝到需要编译的代码的目录。

3 将config.h也拷贝到这个目录,由于unpipc.h依赖于这个头文件。

UNIX网络编程 卷2 源代码使用的更多相关文章

  1. [转载] 读《UNIX网络编程 卷1:套接字联网API》

    原文: http://cstdlib.com/tech/2014/10/09/read-unix-network-programming-1/ 文章写的很清楚, 适合初学者 最近看了<UNIX网 ...

  2. UNIX网络编程 卷2:进程间通信

    这篇是计算机类的优质预售推荐>>>><UNIX网络编程 卷2:进程间通信(第2版)> UNIX和网络专家W. Richard Stevens的传世之作 编辑推荐 两 ...

  3. 《UNIX网络编程 卷1》之"学习环境搭建"(CentOS 7)

    <UNIX网络编程 卷1>的源码可以从www.unpbook.com下载得到.解压之后的目录为unpv13e. 详细步骤 编译 进入unpv13e目录,按如下步骤编译: ./configu ...

  4. UNIX网络编程卷1 - >环境搭建(ubuntu16.04)

      学习unp网络编程,树上的例子均存在#include“unp.h”,故需要对环境进行配置. 1.到资源页下载www.unpbook.com 2.解压并将unpv13e移动到相应的文件夹下 (因为我 ...

  5. 【unp】unix网络编程卷1-->环境搭建(ubuntu14.04)

    学习unp网络编程,树上的例子均存在#include "unp.h",故需要对环境进行配置. 1. 到资源页下载unpv13e 2. 解压并将unpv13e 移动到相应的文件夹下 ...

  6. 《UNIX网络编程 卷1:套接字联网API》读书笔记(一):网络编程简介

    概述 要编写通过计算机网络通信的程序,首先要确定这些程序相互通信所用的协议.大多数网络是按照划分成客户和服务器来组织的.本章及后续章节的焦点是TCP/IP协议族,也可称为网际协议族.下图为客户与服务器 ...

  7. 《Unix网络编程卷1:套接字联网API》读书笔记

    第一部分:简介和TCP/IP 第1章:简介 第2章:传输层:TCP.UDP和SCTP TCP:传输控制协议,复杂.可靠.面向连接协议 UDP:用户数据报协议,简单.不可靠.无连接协议 SCTP:流控制 ...

  8. UNIX网络编程卷1 第一章 简介 读书笔记。

    基本没讲什么,一点点计算机网络发展史,一点点socket()简单介绍,最重要的是1.3节协议无关性. 协议无关性: 贯穿整本书的一个重要特性,他主要强调的是 socket是网络协议无关的编程接口. s ...

  9. UNIX网络编程卷2进程间通信读书笔记(二)—管道 (1)

    一.管道 管道的名称很形象,它就像是一个水管,我们从一端到水然后水从令一端流出.不同的是这里说的管道的两边都是进程.从一端往管道里写数据,其它进程可以从管道的另一端的把数据读出,从而实现了进程间通信的 ...

随机推荐

  1. 转:javascript时间戳和日期字符串相互转换

    转:javascript时间戳和日期字符串相互转换 <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...

  2. Android Service不能再详细的教程

    这篇包含了: Service后台服务.前台服务.IntentService.跨进程服务.无障碍服务.系统服务 几乎所有Android Service相关的东西. 前言 作为四大组件之一的Service ...

  3. leetcode题解之分解字符串域名

    1.题目描述 A website domain like "discuss.leetcode.com" consists of various subdomains. At the ...

  4. phantomJs页面截图

    因为phantomjs使用了一个真正的渲染引擎WebKit,它能截取一个web页面的真实影像,这是因为phantomjs能够折射出WEB页面上的任何东西,包括html,css,svg和Canvas等. ...

  5. vim和xshell配色

    xshell配色: http://www.hookr.cn/xshell-pei-se.html vim配色: 参考该文中的配置方法,包括设置256色等.http://www.cnblogs.com/ ...

  6. 进程间协作---wait,notify,notifyAll

    转自牛客网的一篇评论,解释的十分详细 在 Java 中,可以通过配合调用 Object 对象的 wait() 方法和 notify()方法或 notifyAll() 方法来实现线程间的通信.在线程中调 ...

  7. Invalid argument during startup: unknown conf file parameter : requirepass

    redis 设置来密码,出现来这个错误, 把配置文件那一行的 空格 去掉 # requirepass foobared 改成 requirepass 123456 因为# 和 requirepass ...

  8. 前端 网络三剑客之html 01

    一.引语 1.html是什么? 1.超文本标记语言(Hypertext Markup Language):简称HTML或html.是通过标签语言来标记要显示的网页中的各个部分. 2.它遵循一套浏览器的 ...

  9. c# 利用AForge和百度AI开发实时人脸识别

    baiduAIFaceIdentify项目是C#语言,集成百度AI的SDK利用AForge开发的实时人脸识别的小demo,里边包含了人脸检测识别,人脸注册,人脸登录等功能 人脸实时检测识别功能 思路是 ...

  10. 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置(转)

    安装根据这个配置的,但是opencv3.0安装不成功,后来改安2.48就可以了. http://blog.csdn.net/poem_qianmo/article/details/19809337/ ...