我實際上正試圖將現有的C庫鏈接到我的Cython程序。Cython動態鏈接庫
我訪問聲明爲所有函數庫的入口點頭(.h):
EXPORT_API int _stdcall LibFunction();
我想用來創建__declspec(dllexport)
該DLL EXPORT_API
...
我也有權訪問.lib和.dll文件。
我試圖使用該功能用Cython通常的cdef extern from
:
cdef extern from "include\\entrypoint.h":
int LibFunction()
def c_LibFunction():
LibFunction()
而且我用下面setup.py
from setuptools import setup, Extension
from Cython.Distutils import build_ext
NAME = 'testlib'
REQUIRES = ['cython']
SRC_DIR = 'testlib'
PACKAGES = [SRC_DIR]
INCLUDE_DIR = 'testlib\include'
LIB_DIR = 'testlib\lib'
ext = Extension(SRC_DIR + '.wrapped',
[SRC_DIR + '/wrapped.pyx'],
include_dirs=[INCLUDE_DIR],
library_dirs = [LIB_DIR],
libraries=['cfunc', 'MyLib']
)
if __name__ == "__main__":
setup(
install_requires=REQUIRES,
packages=PACKAGES,
name=NAME,
ext_modules=[ext],
cmdclass={"build_ext": build_ext}
)
但是,當我編譯我用Cython python setup.py build_ext
我得到一個無法解析的外部參考:
error LNK2001: unresolved external symbol __imp_LibFunction
正如我在other thread上找到的,它似乎是一個靜態或動態庫鏈接的問題。
我認爲它來自setuptools編譯選項,我試圖調查使用distutils documentation和Cython documentation。
的事情是,我也試圖做我自己的C庫(cfunc.lib,靜態的),我成功地使用功能它,我與上述相同的方法。
我也MYLIB.LIB使用DUMPBIN
,我發現了個符號int __cdecl LibFunction(void)
和預期,__imp_
不在符號。
它有人發生了什麼事情,爲什麼它是怎麼回事,我怎麼能解決我的問題,也可能是非常有幫助的想法!