当前位置: 技术问答>linux和unix
关于消息队列编译通不过的问题,多谢。
来源: 互联网 发布时间:2015-07-01
本文导语: 我按书上写了一个消息队列的例子。 #define MSGSIZE 256 #define KEY_VALUE 101 #include #include #include #include struct msgbuf1 { long mtype; char mtext[MSGSIZE] ; } main() { int msqid ; int key ; struct msgbuf1 sndbuf,rcvbuf ; key = KE...
我按书上写了一个消息队列的例子。
#define MSGSIZE 256
#define KEY_VALUE 101
#include
#include
#include
#include
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("msggetn");
exit(1);
}
if( msgrecv(msqid , &rcvbuf, MSGSIZE , 2L, 0) == -1)
{
perror("msgrcv");
exit(2);
}
fprintf(stderr,"server got %s from clientn",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文件。。我该怎么做啊?多谢!
#define MSGSIZE 256
#define KEY_VALUE 101
#include
#include
#include
#include
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("msggetn");
exit(1);
}
if( msgrecv(msqid , &rcvbuf, MSGSIZE , 2L, 0) == -1)
{
perror("msgrcv");
exit(2);
}
fprintf(stderr,"server got %s from clientn",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文件。。我该怎么做啊?多谢!
|
msgrecv 改为 msgrcv
IPC_CREAT/06666 -> IPC_CREAT_|0666
IPC_CREAT/06666 -> IPC_CREAT_|0666
|
UP
|
同意
|
hehe...