Reputation: 137662
I tried to write a Cython wrapper around the C++ library http://primesieve.org/
It wraps a single function count
. So far, it installs correctly python setup.py install
, but when I import primesieve
the function primesieve.count
is missing. Any ideas?
primesieve.pxd (following http://docs.cython.org/src/tutorial/clibraries.html)
cdef extern from "stdint.h":
ctypedef unsigned long long uint64_t
cdef extern from "primesieve/include/primesieve.h":
uint64_t primesieve_count_primes(uint64_t start, uint64_t stop)
primesieve.pyx
cimport primesieve
cpdef int count(self, int n):
return primesieve.primesieve_count_primes(1, n)
setup.py
from setuptools import setup, Extension
from Cython.Build import cythonize
setup(
ext_modules = cythonize([Extension("*", ["primesieve.pyx"], include_dirs = ["primesieve/include"])])
)
Upvotes: 3
Views: 285
Reputation: 54213
Modify setup.py
to link against libprimesieve.so
by adding libraries = ["primesieve"]
to you arguments to the Extension
constructor. Without it, you'll get this error:
ImportError: ./primesieve.so: undefined symbol: primesieve_count_primes
Once I changed setup.py
, it worked for me:
$ python2 setup.py build
...
$ (cd build/lib.linux-x86_64-2.7 && python2 -c 'import primesieve; print primesieve.count(None, 5)')
3
Upvotes: 2