简体   繁体   English

通过GCC为Win64的Python扩展

[英]Python extensions for Win64 via GCC

Has anyone had any luck with compiling 64-bit Python extension modules for Windows using mingw64? 有没有人有幸使用mingw64为Windows编译64位Python扩展模块?

I have successfully compiled the extension in question with VS2008 for this platform. 我已成功使用VS2008为此平台编译了相关扩展。 I've also compiled it with mingw32 (with a 32-bit python). 我也用mingw32(用32位python)编译它。 I would prefer both builds to use GCC. 我希望两个版本都使用GCC。

I've installed the mingw64-x86_64-w64 GCC 4.5.1 set of tools using Cygwin and convinced Python to use them. 我使用Cygwin安装了mingw64-x86_64-w64 GCC 4.5.1工具集,并说服Python使用它们。 However, linking to python itself failed. 但是,链接到python本身失败了。

So I picked up pexports 0.44, used it to dump out a python26.def file and create libpython26.a . 所以我选择了pexports 0.44,用它来转储python26.def文件并创建libpython26.a

Now, as in this question , the only link error I'm getting from Python is about __imp_py_InitModule4 . 现在,正如在这个问题中 ,我从Python获得的唯一链接错误是关于__imp_py_InitModule4 Browsing through the def file, I see a Py_InitModule4_64 symbol. 浏览def文件,我看到一个Py_InitModule4_64符号。

Any ideas? 有任何想法吗?

I find you need to define MS_WIN64 as well as WIN32, also the distutils package does not understand mingw64, see this post, and this one 我发现你需要定义MS_WIN64以及WIN32,也就是distutils包不懂mingw64,看到这个帖子, 一个

Patching distutils to support mingw64 is fairly trivial. 修补distutils以支持mingw64是相当微不足道的。

There is a mechanism in Python to prevent linking a module against the wrong version of the library. Python中有一种机制可以防止将模块与错误的库版本链接起来。 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) : 当库/模块针对64位体系结构进行编译时,Py_InitModule4函数被重命名为Py_InitModule4_64(通过宏)(请参阅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

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. 因此,如果您收到此错误,这意味着您的Python库或Python模块是针对32位架构编译的,而另一个是针对64位架构编译的。

See 64BitCythonExtensionsOnWindows on the Cython wiki. 64BitCythonExtensionsOnWindows在用Cython维基。 They recommend against using MinGW-64. 他们建议不要使用MinGW-64。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM