UNP(2rd)第二卷源码编译问题及解决

 
UNP(2rd)第二卷源码编译 问题及解决

转自:http://www.cnblogs.com/westfly/archive/2011/07/28.html


按照README中的操作,先configure,然后进入lib目录下make报错

gcc -g -O2 -D_REENTRANT -Wall -D_POSIX_PTHREAD_SEMANTICS   -c -o daemon_inetd.o daemon_inetd.c
In file included from /usr/include/netinet/in.h:24,
                 from /usr/include/rpc/types.h:91,
                 from /usr/include/rpc/rpc.h:38,
                 from unpipc.h:115,
                 from daemon_inetd.c:1:
/usr/include/stdint.h:49: error: duplicate ‘unsigned’
/usr/include/stdint.h:49: error: two or more data types in declaration specifiers
/usr/include/stdint.h:50: error: duplicate ‘unsigned’
/usr/include/stdint.h:50: error: duplicate ‘short/usr/include/stdint.h:52: error: duplicate ‘unsigned’
/usr/include/stdint.h:52: error: two or more data types in declaration specifiers
make: *** [daemon_inetd.o] Error 1

解决方法

vim ../config.h

注释掉,再make

//#define uint8_t unsigned char               /* <sys/types.h> */

//#define uint16_t unsigned short             /* <sys/types.h> */

//#define uint32_t unsigned int               /* <sys/types.h> */

cd ../pipe

make pipeconf

出现链接警告。

gcc -g -O2 -D_REENTRANT -Wall   -c -o pipeconf.o pipeconf.c
gcc -g -O2 -D_REENTRANT -Wall -o pipeconf pipeconf.o ../libunpipc.a -lrt -lpthread 
../libunpipc.a(wrapunix.o): In function `Mktemp':
/home/cherish/virtual/unpv22e/lib/wrapunix.c:184: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'

mktemp是私有实现,修改为mkstemp就好了。

vim ../wrapunix.c

 //if (mktemp(template) == NULL || template[0] == 0)   
if (mkstemp(template) == -1 || template[0] == 0)          
             err_quit("mktemp error");                         

再次make,警告消失。

编译svmsg目录下的源码

ctl.c:10: error: ‘MSG_R’ undeclared (first use in this function)
……
ctl.c:10: error: ‘MSG_W’ undeclared (first use in this function)
ctl.c:18: error: ‘ulong_t’ undeclared (first use in this function)

在config.h中添加

typedef unsigned long ulong_t;
#define MSG_R 0400
#define MSG_W 0200

再次编译,出现

gcc -g -O2 -D_REENTRANT -Wall -I ../lib -c -o ctl.o ctl.c
ctl.c: In function ‘main’:
ctl.c:8: error: storage size of ‘buf’ isn’t known
ctl.c:8: warning: unused variable ‘buf’
make: *** [ctl.o] Error 1


参考http://bbs.unixbeta.com/viewthread.php?tid=48666
不能用#define __USE_GNU
而应该是:
#define _GNU_SOURCE
__USE_GNU是双划线。
在config.h中添加

#define _GNU_SOURCE

编译消息

mq_open老是失败。由于程序截取了错误码,无法定位。

查资料才发现,可能mq_open失败的错误码: EINVAL,错误信息:Invalid argument

帮助文档的解释如下:

View Code
EINVAL O_CREAT was specified in oflag, and attr was not NULL, but
attr->mq_maxmsg or attr->mq_msqsize was invalid. Both of these
fields must be greater than zero. In a process that is unprivi‐
leged (does not have the CAP_SYS_RESOURCE capability),
attr->mq_maxmsg must be less than or equal to the msg_max limit,
and attr->mq_msgsize must be less than or equal to the msg‐
size_max limit. In addition, even in a privileged process,
attr->mq_maxmsg cannot exceed the HARD_MAX limit. (See mq_over‐
view(7) for details of these limits.)

于是查看,发现

cherish@Ares:~/virtual/unpv22e/pxmsg$ cat /proc/sys/fs/mqueue/msg_max
10
cherish@Ares:~/virtual/unpv22e/pxmsg$ cat /proc/sys/fs/mqueue/msgsize_max
8192

原来是自己输入的msg_max 超过了10.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值