What happened to my Keaton?
I tried to write a Cython wrapper around the C ++ library http://primesieve.org/
It wraps one function count
. So far it installs correctly python setup.py install
, but when I am import primesieve
missing the function primesieve.count
. Any ideas?
primesieve.pxd (after 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"])])
)
source to share
Modify setup.py
to bind to libprimesieve.so
by adding libraries = ["primesieve"]
constructor arguments to you Extension
. Without it, you will get this error:
ImportError: ./primesieve.so: undefined symbol: primesieve_count_primes
Once I changed setup.py
, this 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
source to share