2013-07-24 47 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」的位置

相關問題