免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4575 | 回复: 2
打印 上一主题 下一主题

关于posix消息队列接口mq_open的两个问题 [复制链接]

论坛徽章:
2
程序设计版块每日发帖之星
日期:2016-08-10 06:20:00每日论坛发贴之星
日期:2016-08-10 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-21 22:29 |只看该作者 |倒序浏览
如下这段代码如果用g++当成C++编译就可以编译过去,命令如下:
  g++ -lrt main.cpp
  但是如果用gcc当成C语言编译就编译不过去,命令如下:
  gcc -lrt main.c
  提示的错误如下:
    main.c: In function ‘main’:
    main.c:17: error: ‘S_IREAD’ undeclared (first use in this function)
    main.c:17: error: (Each undeclared identifier is reported only once
    main.c:17: error: for each function it appears in.)
    main.c:17: error: ‘S_IWRITE’ undeclared (first use in this function)

另外,即使用g++编译过去了,运行时也会提示"mq_open: Permission denied".
请各位大侠帮忙解决一下子,兄弟这里先谢啦!


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mqueue.h>

int main(void)
{
    struct mq_attr mattr = {
    0,
        5,
        10,
    };   
    mqd_t mqid;
   
    mqid = mq_open("/tmp/itk_av_msg",
                                O_CREAT | O_RDWR,
                                S_IREAD | S_IWRITE,
                                &mattr);
                                
    if((mqd_t)-1 == mqid)
    {
        perror("mq_open");
        exit(1);
    }
}


[ 本帖最后由 ytsmtipe 于 2009-7-22 09:32 编辑 ]

论坛徽章:
2
程序设计版块每日发帖之星
日期:2016-08-10 06:20:00每日论坛发贴之星
日期:2016-08-10 06:20:00
2 [报告]
发表于 2009-07-22 08:17 |只看该作者
自己顶一下!

论坛徽章:
0
3 [报告]
发表于 2009-07-22 10:55 |只看该作者
http://bbs.chinaunix.net/viewthread.php?tid=1017072
看看这个
加上sys/stat.h头文件试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP