/include/sys/types.h:151: error: duplicate 'unsigned' uint,ulong和ushort自定义和工具链报冲突的规避方法

本文解决在使用glibc-oabi工具链时遇到的重复定义问题,通过提供两种规避方法来解决该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错如下:

/opt/compiler/glibc-oabi-toolchain-arm-generic/arm-unknown-linux-gnu//sys-root/usr/include/sys/types.h:151: error: duplicate 'unsigned'

/opt/compiler/glibc-oabi-toolchain-arm-generic/arm-unknown-linux-gnu//sys-root/usr/include/sys/types.h:152: error: duplicate 'unsigned'
/opt/compiler/glibc-oabi-toolchain-arm-generic/arm-unknown-linux-gnu//sys-root/usr/include/sys/types.h:152: error: duplicate 'short'
/opt/compiler/glibc-oabi-toolchain-arm-generic/arm-unknown-linux-gnu//sys-root/usr/include/sys/types.h:153: error: duplicate 'unsigned'

/opt/compiler/glibc-oabi-toolchain-arm-generic/arm-unknown-linux-gnu//sys-root/usr/include/sys/types.h:153: error: two or more data types in declaration specifiers


总算找到根本原因了:

#include<sys/types.h>  

头文件包含这个啦,这个你去掉就可以了,不去掉就用下面的规避方式就可以解决。


规避方法一:

/*屏蔽掉和工具链里面的重复定义,因为工具链中默认让宏定义__USE_MISC生效*/
#ifndef __USE_MISC


#ifndef uint
#define uint unsigned int
#endif


#ifndef ulong
#define ulong unsigned long
#endif


#ifndef ushort
#define ushort unsigned short
#endif


#endif


规避方法二:直接屏蔽掉

#ifdef __USE_MISC
/* Old compatibility names for C types.  */
//typedef unsigned long int ulong;
//typedef unsigned short int ushort;
//typedef unsigned int uint;
#endif





/root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:29:5: error: type name requires a specifier or qualifier __uint(type, BPF_MAP_TYPE_HASH); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:29:12: error: a parameter list without types is only allowed in a function definition __uint(type, BPF_MAP_TYPE_HASH); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:30:5: error: type name requires a specifier or qualifier __uint(max_entries, 1024); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:30:25: error: expected identifier __uint(max_entries, 1024); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:30:5: error: duplicate member '__uint' __uint(max_entries, 1024); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:29:5: note: previous declaration is here __uint(type, BPF_MAP_TYPE_HASH); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:31:5: error: type name requires a specifier or qualifier __type(key, struct flow_key); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:31:17: error: expected identifier __type(key, struct flow_key); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:32:5: error: type name requires a specifier or qualifier __type(value, __u8); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:32:19: error: unexpected type name '__u8': expected identifier __type(value, __u8); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:32:12: error: a parameter list without types is only allowed in a function definition __type(value, __u8); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:32:5: error: duplicate member '__type' __type(value, __u8); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:31:5: note: previous declaration is here __type(key, struct flow_key); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:37:5: error: type name requires a specifier or qualifier __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_kern.c:37:12: error: a parameter list without types is only allowed in a function definition __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); ^ 16 errors generated.
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值