/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查到的很多页面都没有具体的解决方案,哪位朋友遇到这样的问题参考一下上面的办法吧。