通过GCC Python扩展为Win64的 [英] Python extensions for Win64 via GCC

查看:467
本文介绍了通过GCC Python扩展为Win64的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有任何运气与编译64位Python扩展模块,Windows中使用mingw64?

Has anyone had any luck with compiling 64-bit Python extension modules for Windows using mingw64?

我已经成功编译扩展的问题与VS2008这个平台。我也编译它的mingw32(带有32位蟒蛇)。我想preFER双方建立使用GCC。

I have successfully compiled the extension in question with VS2008 for this platform. I've also compiled it with mingw32 (with a 32-bit python). I would prefer both builds to use GCC.

我已经安装了mingw64-x86_64的-W64 GCC 4.5.1一套使用Cygwin工具和说服Python来使用它们。然而,链接到Python本身失败。

I've installed the mingw64-x86_64-w64 GCC 4.5.1 set of tools using Cygwin and convinced Python to use them. However, linking to python itself failed.

于是我拿起pexports 0.44,用它来倾倒出 python26.def 文件,并创建 libpython26.a

So I picked up pexports 0.44, used it to dump out a python26.def file and create libpython26.a.

现在,在<一个href="http://stackoverflow.com/questions/2842469/python-undefined-reference-to-imp-py-initmodule4">this问题,唯一的链接错误我是从Python中获得约 __ imp_py_InitModule4 。通过DEF文件浏览,我看到一个 Py_InitModule4_64 符号。

Now, as in this question, the only link error I'm getting from Python is about __imp_py_InitModule4. Browsing through the def file, I see a Py_InitModule4_64 symbol.

任何想法?

推荐答案

在Python的机制,以prevent连接了错误版本的库模块。该Py_InitModule4功能(通过宏)更名为Py_InitModule4_64当库/模块编译为64位体系结构(见modsupport.h):

There is a mechanism in Python to prevent linking a module against the wrong version of the library. The Py_InitModule4 function is renamed to Py_InitModule4_64 (via a macro) when the library / module is compiled for a 64-bit architecture (see modsupport.h) :

#if SIZEOF_SIZE_T != SIZEOF_INT
/* On a 64-bit system, rename the Py_InitModule4 so that 2.4
   modules cannot get loaded into a 2.5 interpreter */
#define Py_InitModule4 Py_InitModule4_64
#endif

所以,如果你得到这个错误,这意味着无论你的Python库,或者你的Python模块编译为32位架构,而另一个被编译为64位架构。

So, if you're getting this error, this means either your Python library, or your Python module is compiled for a 32-bit architecture while the other one is compiled for a 64-bit architecture.

这篇关于通过GCC Python扩展为Win64的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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