title: How to compile .c code from Cython with gcc
body: <p>Now that I've successfully installed Cython on Windows 7, I try to compile some Cython code using Cython, but gcc makes my life hard.</p>
  
  <pre><code>cdef void say_hello(name):
      print "Hello %s" % name
  </code></pre>
  
  <p>Using gcc to compile the code throws dozens of <strong>undefined reference to</strong> -erros, and I'm pretty sure the <code>libpython.a</code> is available (as the installation tutorial said, <em>undefined reference to</em> -errors are thrown if this file is missing).</p>
  
  <pre><code>$ cython ctest.pyx
  $ gcc ctest.c -I"C:\Python27\include"
  </code></pre>
  
  <p></p>
  
  <pre><code>C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1038): undefined reference to `_imp__PyString_FromStringAndSize'
  C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1075): undefined reference to `_imp___Py_TrueStruct'
  C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1086): undefined reference to `_imp___Py_ZeroStruct'
  C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1099): undefined reference to `_imp___Py_NoneStruct'
  C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x10b8): undefined reference to `_imp__PyObject_IsTrue'
  c:/program files/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>The weird thing is, using <code>pyximport</code>* or a <code>setup</code>-script works pretty fine, but it's both not very handy when still working on a module.
  <br/>
  <br/></p>
  
  <h2><strong>How to compile those <code>.c</code> files generated with Cython using gcc ?</strong></h2>
  
  <p><em>or any other compiler, important is that it will work !</em></p>
  
  <p><br/></p>
  
  <p><code>*pyximport</code>: Is it normal that only python-native functions and classes are contained in the imported module and not cdef-functions and classes ?
  like:</p>
  
  <pre><code># filename: cython_test.pyx
  cdef c_foo():
      print "c_foo !"
  def foo():
      print "foo !"
      c_foo()
  </code></pre>
  
  <p></p>
  
  <pre><code>import pyximport as p; p.install()
  import cython_test
  cython_test.foo()
  # foo !\nc_foo !
  cython_test.c_foo()
  # AttributeError, module object has no attribute c_foo
  </code></pre>
  
  <p><br/></p>
  
  <h2><strong>UPDATE</strong></h2>
  
  <p>Calling <code>$ gcc ctest.c "C:\Python27\libs\libpython27.a"</code> kills the <strong>undefined reference to</strong> -erros, but this one:</p>
  
  <pre><code>c:/program files/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
  </code></pre>