UNP(2rd)第二卷源码编译
源码下载地点:
http://www.kohala.com/start/unpv22e/unpv22e.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中添加
#define 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
帮助文档的解释如下:
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.