您的位置:首页 > 编程语言

X86_64下源代码编译的一个问题

2007-07-03 23:24 281 查看
前段时间编译了几个源代码包,因为我的机器是X86_64的,所以出现了一个64位系统的问题,折腾了些时间才解决。记录在此,以防忘记。

问题的表现如下:

/usr/include/asm-x86_64/types.h:22: error: conflicting types for 'int64_t'

/usr/include/sys/types.h:198: error: previous declaration of 'int64_t' was here

/usr/include/asm-x86_64/types.h:23: error: conflicting types for 'u_int64_t'

/usr/include/sys/types.h:206: error: previous declaration of 'u_int64_t' was here

头文件asm-x86_64/types.h和sys/types.h的int64_t、u_int64_t定义有冲突,原因是头文件asm-x86_64/types.h在定义int64_t等时没有防止重复定义,而sys/types.h头文件在定义int64_t等时是有防止重复定义的措施的。将asm/types.h(其中包含了asm-x86_64/types.h)放到所有头文件的前面包含,解决问题。

另外,sys/types.h的防止重复定义的代码有个漏洞,只对有符号的类别的类型定义有防止重复定义的代码,如下所示:

# ifndef __int8_t_defined

# define __int8_t_defined

__intN_t (8, __QI__);

__intN_t (16, __HI__);

__intN_t (32, __SI__);

__intN_t (64, __DI__);

# endif

__u_intN_t (8, __QI__);

__u_intN_t (16, __HI__);

__u_intN_t (32, __SI__);

__u_intN_t (64, __DI__);

因此需要将无符号的类别的类型定义也加上防止重复定义的代码,如下所示:

# ifndef __int8_t_defined

# define __int8_t_defined

__intN_t (8, __QI__);

__intN_t (16, __HI__);

__intN_t (32, __SI__);

__intN_t (64, __DI__);

# endif

# ifndef __u_int8_t_defined

# define __u_int8_t_defined

__u_intN_t (8, __QI__);

__u_intN_t (16, __HI__);

__u_intN_t (32, __SI__);

__u_intN_t (64, __DI__);

#endif

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐