当前位置: 技术问答>linux和unix
急,关于posix消息队列!!!
来源: 互联网 发布时间:2017-04-25
本文导语: 文件包含,为什么用gcc编译显示函数未定义??? /tmp/ccc10ZBt.o: In function `main': mqcreatel.c:(.text+0x93): undefined reference to `mq_open' mqcreatel.c:(.text+0xa1): undefined reference to `mq_close' collect2: ld returned 1 exit status #include ...
文件包含,为什么用gcc编译显示函数未定义???
/tmp/ccc10ZBt.o: In function `main':
mqcreatel.c:(.text+0x93): undefined reference to `mq_open'
mqcreatel.c:(.text+0xa1): undefined reference to `mq_close'
collect2: ld returned 1 exit status
#include
#include
#include
#include
#define MQ_FILE "/mq_test"
#define BUF_LEN 128
int main(void)
{
mqd_t mqd;
char buf[BUF_LEN];
int por = 0;
int ret = 0;
struct mq_attr attr;
attr.mq_flags = 0;
attr.mq_maxmsg = 3;
attr.mq_msgsize = 50;
attr.mq_curmsgs= 0;
mqd = mq_open(MQ_FILE, O_WRONLY,0666,&attr);
if (-1 == mqd)
{
printf("mq_open error.n");
return -1;
}
do{
buf[BUF_LEN-1]='';
printf("MQ_MSG : ");
scanf("%s", buf);
if(buf[BUF_LEN-1]!= '')
{
continue;
}
printf("strlen:%dnMQ_POR : ",strlen(buf));
scanf("%d", &por);
ret== mq_send(mqd, buf, strlen(buf)+1, por);
if (ret != 0)
{
perror("mq_send error.n");
}
memset(buf,'',BUF_LEN);
}while(strcmp(buf, "quit"));
mq_close(mqd);
mq_unlink(MQ_FILE);
return 0;
}
|
NAME
mq_open - open a message queue
SYNOPSIS
#include /* For O_* constants */
#include /* For mode constants */
#include
mqd_t mq_open(const char *name, int oflag);
mqd_t mq_open(const char *name, int oflag, mode_t mode,
struct mq_attr *attr);
Link with -lrt.
mq_open - open a message queue
SYNOPSIS
#include /* For O_* constants */
#include /* For mode constants */
#include
mqd_t mq_open(const char *name, int oflag);
mqd_t mq_open(const char *name, int oflag, mode_t mode,
struct mq_attr *attr);
Link with -lrt.