title: declaring i2c_msg yields gcc error: array type has incomplete element type
body: <p>I am generating a couple of wrapper files for i2c communication. these are written in C.</p>
  
  <p>The header file looks like:</p>
  
  <pre><code>#ifndef IMX6QI2C_WRAPPER_H_
  #define IMX6QI2C_WRAPPER_H_
  
  #include &lt;linux/i2c-dev.h&gt; //contains definitions for:
                                     struct i2c_msg
                                     struct i2c_rdwr_ioctl_data
  
  //fn declarations
  
  #endif /* IMX6QI2C_WRAPPER_H_ */
  </code></pre>
  
  <p>the source file contains:</p>
  
  <pre><code>#include "imx6qi2c_wrapper.h"
  #include &lt;stdio.h&gt;    //printf()
  #include &lt;unistd.h&gt;    //for close()
  #include &lt;string.h&gt;    //for MANY implicit decl. &amp; -Wformat errs
  #include &lt;sys/types.h&gt; //open()
  #include &lt;sys/stat.h&gt;  //open()
  #include &lt;fcntl.h&gt;     //open(),O_RDWR
  #include &lt;sys/ioctl.h&gt; //ioctl()
  #include &lt;errno.h&gt;     //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,&amp;i2cmsg,I2CMSGS_TOTAL_WR);
  
      //do more stuff
  }
  </code></pre>
  
  <p>now, compiler is fine with the definition of "imxSend_i2cMsg()", as far as <code>struct i2c_msg *i2cMsgArray</code> is concerned.</p>
  
  <p>But it has a problem with the declaration of the local variable <code>struct i2c_msg i2cmsg[2]</code>, in function "imxSend_i2cByte()".</p>
  
  <p>The error is : "array type has incomplete element type".</p>
  
  <p>And I am left wondering.</p>
  
  <p>Could it possibly be related to #include directives?
  In my example, <code>i2c-dev.h</code> that contains the definitions of "struct i2c_msg", is #included in <code>i2c_wrapper.h</code> and the latter is then included in the <code>i2c_wrapper.c</code> file. To my understanding, this means that the source file CAN indeed "see" the "struct i2c_msg". No?</p>
  
  <p>I have seen this question on numerous occasions in stackoverflow but the answer is still not obvious. Can someone point me in the right direction?</p>
  
  <p>Thank you for your help.</p>