title: Matlab with external C++ function: coder.ceval pass a structure to a function
body: <p>I’m trying to pass a Structure from a Matlab function in Simulink to an external C++ function using the coder.ceval() and the coder.cstructname(). When I try to run the code on an Arduino Due board using the deploy to hardware tool in Simulink I get the error:  </p>
  
  <pre><code>error: invalid use of incomplete type 'struct MyStruct' 
  error: forward declaration of 'struct MyStruct'
  </code></pre>
  
  <p>I’m using the example code from mathworks but use a c++ function instead of a c function:</p>
  
  <p>Header use_struct.h:</p>
  
  <pre><code>#include &lt;tmwtypes.h&gt;
  
  typedef struct MyStruct
  {
      double s1;
      double s2;
  } MyStruct;
  
  void use_struct(struct MyStruct *my_struct);
  </code></pre>
  
  <p>C++ function use_struct.cpp:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
   #include &lt;stdlib.h&gt;
  // #include "use_struct.h"  // Doesn’t work when I include it here
  
  
  extern “C” void use_struct(struct MyStruct *my_struct)
  {
    double x = my_struct-&gt;s1;
    double y = my_struct-&gt;s2;
  }
  </code></pre>
  
  <p>Matlab function:</p>
  
  <pre><code>structVar.s1 = 1;
  structVar.s2 = 2;
  
  if strcmp(coder.target,'rtw'),
  
  
  coder.cinclude('use_struct.h');
  coder.cstructname(structVar, 'MyStruct', 'extern');
  
  coder.ceval('use_struct', coder.ref(structVar));
  
  end
  </code></pre>
  
  <p>I need it to be a C++ function for the later code. However I also tried it with a c function without the extern “C” but it doesn’t work anyway. Can anyone help me with this problem?</p>