I am trying to use Cython to expose a function from a static library to python. I have a myLibrary.lib
and a myLibrary.dll
file, but no header file. In the library, there is a function/symbol named myFunc
.
So I wrote my core.pxd
file:
cdef extern short myFunc(char*, short*, int*, float*, short*)
And my core.pyx
file:
import numpy as np
cimport numpy as np
def get_data(char[:] path, int istart, int iend):
cdef short err = 0
cdef int[:] pts = np.arange(istart, iend, dtype=np.int32)
cdef short nPts = <short>pts.shape[0]
cdef float[:,:,:] out = np.zeros((nPts, 11, 18), dtype='f4')
myFunc(&path[0], &nPts, &pts[0], &out[0,0,0], &err)
return np.asarray(out)
Which I am finally building using:
from setuptools import setup, Extension
from Cython.Build import cythonize
import numpy
setup(
ext_modules = cythonize([
Extension('mymodule.core', ['mymodule/core.pyx'],
include_dirs=[numpy.get_include()],
libraries=['myLibrary'],
library_dirs=['mymodule'],
)
])
)
Which I then run using:
python setup.py build_ext --inplace
However, it gives me the error:
core.obj : error LNK2001: unresolved external symbol _myFunc
It seems to be searching for the symbol _myFunc
rather than myFunc
. How can I prevent Cython from searching for a underscore-prefixed symbol and just use the symbol as I specified?
I am using 32-bit python 3.6, the library is 32-bit, and I have installed 32-bit versions of numpy and Cython. The library files (dll and lib) are in the same directory as the core.pyx
file.