Cython和distutils [英] Cython and distutils

查看:160
本文介绍了Cython和distutils的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Cython将多个.pyx文件转换为可执行程序包(.DLL)。

I want to use Cython to convert multiple .pyx files into an executable package (.DLL).

如何从多个.pyx创建单个Windows DLL通过distutils?

How do I create a single Windows DLL from multiple .pyx via distutils?

使用的示例:

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)

init .py:

cimport sub1
cimport sub2

import sub1
import sub2

设置。 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


推荐答案

我不知道这一点:

http:// groups。 google.com/group/cython-users/browse_thread/thread/cbacb7e848aeec31

我报告了cython的一位主要编码员(Lisandro Dalcin)的回答(很抱歉,交叉发布):

I report the answer of one of the main coders (Lisandro Dalcin) of cython (sorry for cross posting):

ext_modules=[ 
    Extension("myModule", 
              sources=['src/MyFile1.pyx', 
                       'src/MyFile2.pyx'], 

您不能具有从两个不同来源构建的单个 myModule。
也许您可以添加 src / myModule.pyx文件,并在下面添加两行

You cannot have a single "myModule" built from two different sources. Perhaps you could add a "src/myModule.pyx" file, with the two lines below:

# file: myModule.pyx 
include "MyFile1.pyx" 
include "MyFile2.pyx" 

,然后使用

Extension("myModule", sources=['src/myModule.pyx'], ...) 

这篇关于Cython和distutils的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆