-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request
Description
-
answer.c
int answer(void) { return 42; }
-
answer.h
int answer(void);
-
answer.pxd
cdef extern from "answer.h": int answer()
-
answer.pyx
cimport answer cpdef test(): return answer()
-
setup.py
import sys from distutils.core import setup from distutils.command.build_clib import build_clib from distutils.extension import Extension from Cython.Distutils import build_ext libanswer = ('answer', {'sources': ['answer.c']}) ext_modules=[ Extension("demo", ["answer.pyx"]) ] def main(): setup( name = 'answer', libraries = [libanswer], cmdclass = {'build_clib': build_clib, 'build_ext': build_ext}, ext_modules = ext_modules ) if __name__ == '__main__': main()
-
test.py
import answer def test_answer(): ret = demo.test() assert(ret == 42) if __name__ == '__main__': test_answer()
-
Build the C library:
$ python setup.py build_clib
-
Build the extension module in place
$ python setup.py build_ext --inplace
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request