我从ADI公司购买了ad7176-2模拟到数字IC的开发板。我下载了“通用驱动程序文件”(不是特定于操作系统的)。 我一直在Raspberry Pi上编译它们,Raspberry Pi是一个运行Debian变体的arm设备,名为Raspian。 我使用Code :: Blocks作为IDE,我使用了“GNU GCC”和“GNU ARM GCC”编译器。
我收到错误“未定义引用'AD7176_regs'
这是来自AD7176_regs.h文件的代码,AD7176.h中包含#included,它在AD7176.c中是#included,编译器发现错误。
代码:
/*! AD7176 register info */
typedef struct _st_reg
{
int32_t addr;
int32_t value;
int32_t size;
}st_reg;
/*! AD7176 registers list*/
enum AD7176_registers
{
Status_Register = 0x00,
ADC_Mode_Register,
Interface_Mode_Register,
Register_Check,
Data_Register,
IOCon_Register,
ID_st_reg,
CH_Map_1,
CH_Map_2,
CH_Map_3,
CH_Map_4,
Setup_Config_1,
Setup_Config_2,
Setup_Config_3,
Setup_Config_4,
Filter_Config_1,
Filter_Config_2,
Filter_Config_3,
Filter_Config_4,
Offset_1,
Offset_2,
Offset_3,
Offset_4,
Gain_1,
Gain_2,
Gain_3,
Gain_4,
Communications_Register,
AD7176_REG_NO
};
**Defining the undefined**
#ifdef AD7176_INIT
/*! Array holding the info for the AD7176 registers - address, initial value, size */
st_reg AD7176_regs[] =
{
{0x00, 0x00, 1}, //Status_Register
{0x01, 0x0000, 2}, //ADC_Mode_Register
{0x02, 0x0100, 2}, //Interface_Mode_Register
{0x03, 0x0000, 3}, //Register_Check
{0x04, 0x0000, 3}, //Data_Register
{0x06, 0x0000, 2}, //IOCon_Register
{0x07, 0x0000, 2}, //ID_st_reg
{0x10, 0x8002, 2}, //CH_Map_1
{0x11, 0x0000, 2}, //CH_Map_2
{0x12, 0x0000, 2}, //CH_Map_3
{0x13, 0x0000, 2}, //CH_Map_4
{0x20, 0x0000, 2}, //Setup_Config_1
{0x21, 0x0000, 2}, //Setup_Config_2
{0x22, 0x0000, 2}, //Setup_Config_3
{0x23, 0x0000, 2}, //Setup_Config_4
{0x28, 0x020A, 2}, //Filter_Config_1
{0x29, 0x0200, 2}, //Filter_Config_2
{0x2a, 0x0200, 2}, //Filter_Config_3
{0x2b, 0x0200, 2}, //Filter_Config_4
{0x30, 0, 3}, //Offset_1
{0x31, 0, 3}, //Offset_2
{0x32, 0, 3}, //Offset_3
{0x33, 0, 3}, //Offset_4
{0x38, 0, 3}, //Gain_1
{0x39, 0, 3}, //Gain_2
{0x3a, 0, 3}, //Gain_3
{0x3b, 0, 3}, //Gain_4
{0xFF, 0, 1} //Communications_Register
};
#else
extern st_reg AD7176_regs[AD7176_REG_NO];
#endif
这是我们想要访问寄存器值的地方之一,但是会收到错误消息。
/***************************************************************************//**
* @brief Reads the conversion result from the device.
*
* @param pData - Pointer to store the read data.
*
* @return Returns 0 for success or negative error code.
*******************************************************************************/
int32_t AD7176_ReadData(int32_t* pData)
{
int32_t ret;
/* Read the value of the Status Register */
ret = AD7176_ReadRegister(&AD7176_regs[Data_Register]);
/* Get the read result */
*pData = AD7176_regs[Data_Register].value;
return ret;
}
如果我修复此问题,我应该使用GCC for ARM还是GCC。代码将在Raspberry Pi上运行并控制开发板上的ADC IC。
谢谢彼得
答案 0 :(得分:3)
显然AD7176_INIT
未定义,因此您最终得到:
extern st_reg AD7176_regs[AD7176_REG_NO];
它声明了AD7176_regs
但没有定义它,这就是你得到链接器未定义引用错误的原因。
现在,对象定义不应出现在头文件中,定义应放在.c
文件中。