OS:Ubuntu16.04 所需源码压缩文件资料unpv22e.tar.gz
1. 源码解压(unpv22.tar.gz就在主目录下):
tar -zxvf unpv22e.tar.gz
2. 编译库文件(进入unpv22e目录)
cd unpv22e
./configure
编辑生成config.h文件,注释以下几行
vim config.h
56 //#define uint8_t unsigned char /*sys/types.h*/
57 //#define uint16_t unsigned short /*sys/types.h*/
56 //#define uint32_t unsigned int /*sys/types.h*/
添加MSG_R和MSG_W定义及相关类型缩写的typedef
vim config.h
67 typedef unsigned long ulong_t
68 typedef unsigned int uint_t
69 #define MSG_R 0400
70 #define MSG_W 0200
添加_GNU_SOURCE定义
vim config.h
71 #define _GNU_SOURCE
修改../unpv22e/lib/wrapunix.c,使用mkstemp函数替换mktemp函数
cd ../lib
181 void
182 Mktemp(char* template)
182{
184 if (mkstemp(template) == NULL || template[0] == 0)
185 err_quit("mktemp error");
186}
编译生成libunpipc.a
cd lib
make //unpv22e/目录下会有libunpipc.a静态连接库文件生成
3. 导入头文件ipcconfig.h和unpipc.h及库文件libunpipc.a
在目录unpv22e/下修改config.h(因为unp1时已用此名称哈!避免重复),copy到/usr/include/下
mv config.h ipcconfig.h
cp ipcconfig.h /usr/include/ipcconfig.h
修改pipe/unpipc.h头文件并copy到/usr/include/下
vim ../pipe/unpipc.h
/* include unpipch */
/* Our own header. Tabs are set for 4 spaces, not 8 */
#ifndef __unpipc_h
#define __unpipc_h
//就是以下这行将../config.h修改为./ipcconfig.h即可
#include "./ipcconfig.h" /* configuration options for current OS */
/* "../config.h" is generated by configure */
将库文件libunpipc.a拷贝到/usr/lib/下
cp ../libunpipc.a /usr/lib/
到这里大功告成。
首先来编译一下第一个源程序,需要添加附加的选项-lunpipc(告诉编译器连接到所生成的静态库文件libunpipc.h) -lrt(试一下不添就会出现许多未定义函数) -lpthread(说实话,这个选项在我第一次编译时烦死了,想不通为什么要加这个)
cd ../pipe
gcc -g mainpipe.c -o mainpipe -lunpipc -lrt -lpthread //哈哈,按提示添加头文件,just do it! 这才大功告成!