2013-07-24 46 views
0

我正在为i2c通信生成几个包装文件。这些被写入C.声明i2c_msg产生gcc错误:数组类型具有不完整的元素类型

头文件看起来像:

#ifndef IMX6QI2C_WRAPPER_H_ 
#define IMX6QI2C_WRAPPER_H_ 

#include <linux/i2c-dev.h> //contains definitions for: 
            struct i2c_msg 
            struct i2c_rdwr_ioctl_data 

//fn declarations 

#endif /* IMX6QI2C_WRAPPER_H_ */ 

源文件包含:

#include "imx6qi2c_wrapper.h" 
#include <stdio.h> //printf() 
#include <unistd.h> //for close() 
#include <string.h> //for MANY implicit decl. & -Wformat errs 
#include <sys/types.h> //open() 
#include <sys/stat.h> //open() 
#include <fcntl.h>  //open(),O_RDWR 
#include <sys/ioctl.h> //ioctl() 
#include <errno.h>  //errno,strerror() 

#define I2CMSGS_TOTAL_WR 1 
#define I2CMSGS_TOTAL_RD 2 
#define I2C_M_WR    0x00 //missing from i2c_msg flags 


int imxSend_i2cMsg(const int i2c_fd, 
        struct i2c_msg *i2cMsgArray, 
        const unsigned int arraySize){ 

    //do stuff 
} 


int imxSend_i2cByte(const int i2c_fd, 
        const unsigned char i2cAddress, 
        const unsigned char devRegister, 
        const unsigned char value){ 

    struct i2c_msg i2cmsg[2]; 

    //do stuff 

    ret=imxSend_i2cMsg(i2c_fd,&i2cmsg,I2CMSGS_TOTAL_WR); 

    //do more stuff 
} 

现在,编译器是细跟 “)imxSend_i2cMsg(” 的定义,至于struct i2c_msg *i2cMsgArray而言。

但是在函数“imxSend_i2cByte()”中声明局部变量struct i2c_msg i2cmsg[2]时出现问题。

错误是:“数组类型具有不完整的元素类型”。

我还在想。

它可能与#include指令有关吗? 在我的示例中,包含“struct i2c_msg”的定义的i2c-dev.h包含在i2c_wrapper.h中,后者包含在i2c_wrapper.c文件中。据我的理解,这意味着源文件可以确实“看到”结构i2c_msg“。没有?

我已经看到了这个问题在很多场合在stackoverflow但答案仍然不明显。有人能指引我朝着正确的方向吗?

谢谢你的帮助。

+0

您能否告诉我们一个最小的完整示例,包括'i2c_msg'的定义? – Beta

回答

0

确定这是我的makefile中的一个错误的“-I”标志。 我没有正确指向“linux/i2c-dev.h”的位置

相关问题