今日在新系统当中编译bison时提示有编译错误:

 今日在新系统当中编译bison时提示有编译错误:
/usr/include/string.h:546: error: expected declaration specifiers or 216; 230; 217; before 216;__locale_t 217;
/usr/include/string.h:547: error: nonnull argument with out-of-range operand number (argument 1, operand 3)
/usr/include/string.h:550: error: expected declaration specifiers or 216; 230; 217; before 216;__locale_t 217;
/usr/include/string.h:55 1: error: nonnull argument with out-of-range operand number (argument 1, operand 4)

    由于新系统刚刚使用了glibc-2.10.1,其中的头文件也是glibc编译以后替换的,于是怀疑glibc库的头文件出现了问题。当然为了排除gcc的错误,在当前环境下重新编译gcc,同样无法通过。遂构造一个简单的.c文件进行编译:
#include <stdio.h>
#include <string.h>

int main(void)
{
        printf("hello\n");
        return 0;
}

    用gcc test.c编译正常,回头查找string.h当中提示错误的地方,发现如果define了__USE_GNU,则编译出错。而bison的源码当中用了define _GNU_SOURCE,同样造成了__USE_GNU的定义。于是用gcc -D_GNU_SOURCE test.c,错误重现。
    查找string.h的错误部分:
extern int strcasecmp_l (__const char *__s1, __const char *__s2,
                        __locale_t __loc)
     __THROW __attribute_pure__ __nonnull ((1, 2, 3));

extern int strncasecmp_l (__const char *__s1, __const char *__s2,
                          size_t __n, __locale_t __loc)
     __THROW __attribute_pure__ __nonnull ((1, 2, 4));

    属性的设置并无问题,怀疑__locale_t没有定义。在/usr/include下查找__locale_t的定义,出现在xlocale.h当中,同时发现在stdlib.h当中已有相关的include。于是尝试将test.c改为:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
        printf("hello\n");
        return 0;
}
    编译无错。于是对比另外一个系统的string.h与当前的string.h的区别,发现在以上两个函数的声明前有一句#include <xlocale.h>,而glibc-2.10.1的string.h头文件内并无这一句。于是加上,测试以后一切ok。
   不知道这个地方是怎么遗漏了。google查到的很多页面都没有具体的解决方案,哪位朋友遇到这样的问题参考一下上面的办法吧。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值