关于消息队列编译通不过的问题,多谢。
我按书上写了一个消息队列的例子。
#define MSGSIZE 256
#define KEY_VALUE 101
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
struct msgbuf1
{
long mtype;
char mtext[MSGSIZE] ;
}
main()
{
int msqid ;
int key ;
struct msgbuf1 sndbuf,rcvbuf ;
key = KEY_VALUE ;
if((msqid = msgget(key,IPC_CREAT/06666)) == -1)
{
printf("msgget\n");
exit(1);
}
if( msgrecv(msqid , &rcvbuf, MSGSIZE , 2L, 0) == -1)
{
perror("msgrcv");
exit(2);
}
fprintf(stderr,"server got %s from client\n",rcvbuf.mtext);
sndbuf.mtype=1 ;
sprintf(sndbuf.mtext, "\"I received your message\"");
puts("server sending message......");
if( msgsnd(msqid, &sndbuf, strlen(sndbuf.mtext)+1,0) == -1)
{
perror("msgsnd") ;
exit(3);
}
sleep(3);
msgctl(msqid, IPC_RMID , NULL);
exit(0);
}
编译之后出现如下结果:
# cc -o testMQ testMQ.c
Undefined first referenced
symbol in file
msgrecv testMQ.o
ld: fatal: Symbol referencing errors. No output written to testMQ
好像是缺少一些lib文件。。我该怎么做啊?多谢!
问题点数:50、回复次数:4Top
1 楼wenlq(when)回复于 2004-07-04 20:34:50 得分 30
msgrecv 改为 msgrcv
IPC_CREAT/06666 -> IPC_CREAT_|0666Top
2 楼dchg2000(偏爱小龙女(http://www.go2linux.cn/))回复于 2004-07-05 13:16:56 得分 10
UPTop
3 楼yiyi1977(yy)回复于 2004-07-05 13:58:38 得分 5
同意Top
4 楼pacman2000(pacman)(影子传说)回复于 2004-07-05 14:28:09 得分 5
hehe...Top




