4
我想使用Cython将多个.pyx文件转换为可执行文件包(.DLL)。Cython和distutils
如何通过distutils从多个.pyx创建单个Windows DLL?
样品使用:
sub1.pyx:
cimport sub1
class A():
def test(self, val):
print "A", val
sub1.pxd:
cdef class A:
cpdef test(self,val)
sub2.pyx:
cimport sub2
class B():
def test(self):
return 5
sub2.pxd:
cdef class B:
cpdef test(self)
初始化的.py:
cimport sub1
cimport sub2
import sub1
import sub2
setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("sub", ["__init__.pyx", "sub1.pyx", "sub2.pyx"])]
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
错误:
sub1.obj : error LNK2005: ___pyx_module_is_main_sub already defined in __init__.obj
sub1.obj : error LNK2005: _initsub already defined in __init__.obj
sub2.obj : error LNK2005: ___pyx_module_is_main_sub already defined in __init__.obj
sub2.obj : error LNK2005: _initsub already defined in __init__.obj
Creating library build\temp.win32-2.7\Release\sub.lib and object build\temp.win32-2.7\Release\sub.exp
C:\temp\ctest\sub\sub.pyd : fatal error LNK1169: one or more multiply defined symbols found
你真的给他解决问题的多种方式,或编辑你已经给出的答案?如果您正在编辑,请清理此文章并使用您想保留的答案下方的“编辑”链接。 – 2012-05-02 10:04:22
问题是因为Opera 11.62无法正常工作。我无法使用回车键在文章编辑中添加换行符。 – 2012-05-02 11:41:42
但是,这将处理所有pyx文件作为一个模块(即将所有符号放入一个名称空间)? – 2012-05-03 05:32:03