title: Call python code from c via cython
body: <p>So I'd like to call some python code from c via cython. I've managed to call cython code from c. And I can also call python code from cython. But when I add it all together, some things are missing.</p>
  
  <p>Here is my python code (<code>quacker.pyx</code>):</p>
  
  <pre><code>def quack():
      print "Quack!"
  </code></pre>
  
  <p>Here is my cython "bridge" (<code>caller.pyx</code>):</p>
  
  <pre><code>from quacker import quack
  
  cdef public void call_quack():
      quack()
  </code></pre>
  
  <p>And here is the c code (<code>main.c</code>):</p>
  
  <pre><code>#include &lt;Python.h&gt;
  #include "caller.h"
  
  int main() {
    Py_Initialize();
    initcaller();
    call_quack();
    Py_Finalize();
    return 0;
  }
  </code></pre>
  
  <p>When I run this I get this exception:</p>
  
  <p><code>Exception NameError: "name 'quack' is not defined" in 'caller.call_quack' ignored</code></p>
  
  <p>The missing pieces I'm suspecting:</p>
  
  <ul>
  <li>I haven't called <code>initquacker()</code></li>
  <li>I haven't included <code>quacker.h</code></li>
  <li>Cython didn't produce any <code>quacker.h</code> - <code>only quacker.c</code></li>
  <li><code>caller.c</code> doesn't import <code>quacker.h</code> or call <code>initquacker()</code></li>
  </ul>
  
  <p>I'm not really sure that it's even possible to do what I'm trying to do, but it seems to me that it ought to be. I'd love to hear any input you might have.</p>
  
  <p>Edit:</p>
  
  <p>This is how I cythonize / compile / link / run:</p>
  
  <pre><code>$ cython *.pyx
  $ cc -c *.c -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
  $ cc -L/System/Library/Frameworks/Python.framework/Versions/2.7/lib -L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl *.o -o main
  $ ./main
  </code></pre>