PYTHON setup.py build_ext --inplace PYTHON -c "import foo" PYTHON -c "import a" PYTHON -c "import b" ######## setup.py ######## from Cython.Build import cythonize from distutils.core import setup setup( ext_modules = cythonize("*.pyx"), ) ######## foo.pxd ######## cdef int bar() except * cdef extern from "bar_impl.c": struct mystruct: int (*func_ptr)(int param) nogil ######## foo.pyx ######## cdef extern from "bar_impl.c": int bar() except * ######## bar_impl.c ######## static int bar() { return -1; } typedef struct mystruct { int (*func_ptr)(int param); } mystruct_t; ######## a.pyx ######## cimport cython from foo cimport bar assert bar() == -1 ######## b.pyx ######## from foo cimport mystruct cdef int cb(int param) noexcept nogil: return param cdef mystruct ms = mystruct(&cb) assert ms.func_ptr(5) == 5