【发布时间】:2022-01-20 02:07:32
【问题描述】:
我正在尝试将符号导出到内核。但我收到以下错误。我的linux版本是5.4.2,
/home/ram/checkout/drivers/char/i2c_sw_hw_common.c: At top level:
/home/ram/checkout/drivers/char/i2c_sw_hw_common.c:1031:14: error: conflicting types for ‘sfp_i2c_in32’
UInt32 sfp_i2c_in32(char_dev_t *dev,unsigned int I2cDevaddr, int alen, unsigned int offset,unsigned int I2cAddr,int Width, int AccessType)
^~~~~~~~~~~~
In file included from /home/ram/checkout/drivers/char/i2c_sw_hw_common.c:3:
/home/ram/checkout/drivers/char/i2c_sw_hw_common.h:123:8: note: previous declaration of ‘sfp_i2c_in32’ was here
UInt32 sfp_i2c_in32(char_dev_t *dev,unsigned int I2cDevaddr, int alen, unsigned int offset,unsigned int I2cAddr,int Width, int AccessType);
^~~~~~~~~~~~
/home/ram/checkout/drivers/char/i2c_sw_hw_common.c: In function ‘sfp_i2c_in32’:
/home/ram/checkout/drivers/char/i2c_sw_hw_common.c:1035:18: warning: unused variable ‘byte_count’ [-Wunused-variable]
unsigned int byte_count = 0 ;
^~~~~~~~~~
/home/ram/checkout/drivers/char/i2c_sw_hw_common.c: At top level:
/home/ram/checkout/drivers/char/i2c_sw_hw_common.c:1063:29: error: conflicting types for ‘sfp_i2c_in32’
EXPORT_SYMBOL_NOVERS(sfp_i2c_in32);
^~~~~~~
In file included from /home/ram/checkout/drivers/char/i2c_sw_hw_common.c:3:
/home/ram/checkout/drivers/char/i2c_sw_hw_common.h:123:8: note: previous declaration of ‘sfp_i2c_in32’ was here
UInt32 sfp_i2c_in32(char_dev_t *dev,unsigned int I2cDevaddr, int alen, unsigned int offset,unsigned int I2cAddr,int Width, int AccessType);
^~~~~~~~~~~~
cc1: some warnings being treated as errors
这是我对这个符号的声明、定义和导出。
i2c_sw_hw_common.c
UInt32 sfp_i2c_in32(char_dev_t *dev,unsigned int I2cDevaddr, int alen, unsigned int offset,unsigned int I2cAddr,int Width, int AccessType)
{
// code
}
EXPORT_SYMBOL(sfp_i2c_in32);
i2c_sw_hw_common.h
UInt32 sfp_i2c_in32(char_dev_t *dev,unsigned int I2cDevaddr, int alen, unsigned int offset,unsigned int I2cAddr,int Width, int AccessType);
【问题讨论】:
-
虽然错误消息显示声明(在标题中)和定义(在源文件中)的签名相同,但它可能是其中使用的类型的不同含义签名。例如。在包含标头和定义函数之间,它可能类似于源文件中的
#define UInt32 int。所以在标头返回值是unsigned int,但在源中它是int。 -
顺便说一句,标题“EXPORT_SYMBOL 宏给出冲突类型错误”是错误的:不是
EXPORT_SYMBOL导致 primary(第一个)错误. -
如果内核已经在
<linux/types.h>中定义了u32(和类似的),我不太确定为什么要重新定义您的类型,例如Uint32?正如 Tsyvarev 提到的,这可能是签名不同的一种方式。尝试更改它,看看错误是否仍然发生。 -
是的,这就是问题所在。我使用了
-save-temps标志并看到了预处理的输出。在定义中,UInt32被翻译成unsigned int,但声明仍然是UInt32。需要检查它为什么会发生。但是现在,我已经从这两个地方删除了UInt32,并用unsigned int替换了它。非常感谢。 -
@Andy J,实际上这段代码是大型驱动程序代码的一部分,我不确定在驱动程序代码中指定用户定义的 typedef
UInt32的原因。
标签: c linux linux-kernel