Calling a Cython Function form C Windowsx64
Question: after a long search without any results, i need some help.

I'm trying to call a Cython function form C. I have the following Code:

**print.pyx**

    
    
    cdef public int grail(int i, int a): # public function declaration
        return (i+a)
    

**modul.c**

    
    
    #include <Python.h>
    #include "print.h"
    #include <stdio.h>
    void main(void) {
        int a;
    
        Py_Initialize();
        initprint();
        a = grail(2,3);
        printf("%i\n", a);
        Py_Finalize();
    }
    

I try two ways to Compile and Link it, and i always fail by linking it.

First with Command Line:

    
    
    cython print.pyx
    gcc -LD:\Anaconda\libs -ID:\Anaconda\include -o print.exe print.c modul.c -lpython27 -g
    

Second with **setup.py**

    
    
    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext
    setup(
        cmdclass = {'build_ext': build_ext},
        ext_modules = [Extension("print", ["print.pyx", "modul.c"])]
    )
    

And then on Command Line:

    
    
    python setup.py build_ext --inplace
    

In both cases i got the same error:

    
    
    build\temp.win32-2.7\Release\modul.o:modul.c:(.text+0x2a): undefined reference t
    o `__imp__grail'
    

Here are some additional information about my system:

Python 2.7.7 :: Anaconda 2.0.1 (32-bit)

gcc (GCC) 4.7.0 20111219

Cython version 0.20.1

Windows 7 Enterprise x64

I hope someone know how i can solve the Problem, but already thank you very
much for your help.

Best regards


Answer: If I were you, I'd start with CFFI instead of writing this manually:

<http://eli.thegreenplace.net/2013/03/09/python-ffi-with-ctypes-and-cffi>

I'm not sure how well it works on Windows, though (it worked perfectly on
Linux for me). It might work since CFFI project claims this about windows:

<http://cffi.readthedocs.org/en/release-0.8/#windows-64>

