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

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

问题描述

有没有人使用 mingw64 为 Windows 编译 64 位 Python 扩展模块?

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

我已经成功地使用 VS2008 为这个平台编译了有问题的扩展.我还使用 mingw32(使用 32 位 python)编译了它.我更喜欢两个版本都使用 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.

我已经使用 Cygwin 安装了 mingw64-x86_64-w64 GCC 4.5.1 工具集并说服 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.

现在,就像在这个问题中一样,唯一的链接错误我从 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 中有一种机制可以防止将模块链接到错误版本的库.当为 64 位架构编译库/模块时,Py_InitModule4 函数被重命名为 Py_InitModule4_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 的 Win64 的 Python 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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