I often cimport C libraries for use in my own Cython modules. Good recent examples are MPFR and GSL. I am however confused how Cython handles *.pxd files, and how I have to comp/link the Cython modules.
Let's say I have someImports.pxd
which looks like this
cdef extern from "mpfr.h":
ctypedef unsigned int mpfr_prec_t
void mpfr_set_default_prec(mpfr_prec_t prec) nogil
To be able to use this in other modules, the other modules have to comp/link with the MPFR library. If I write a tiny wrapper function (even inline!) in someImports.pyx
, then I don't have to do this.
I'm talking about basically the extra_compile_args and extra_link_args in my setup.py
.
extensions = [Extension("someImports", ["someImports.pyx"],
extra_compile_args = ['-lmpfr','-lgmp'],
extra_link_args = ['-lmpfr','-lgmp']
),
Extension("useImports", ["useImports.pyx"],
extra_compile_args = ['-lmpfr','-lgmp'], # Need this when no wrapper function in someImports.pyx
extra_link_args = ['-lmpfr','-lgmp'] # Need this when no wrapper function in someImports.pyx
)
]
In useImports.pyx
I just cimport the someImports
and well, call the functions.
Seems to me this is slightly weird behavior, so I think I might be missing something.
The "full" test example can be found in a github https://github.com/oliverhaas/cython_lib_import