通过GCC为Win64的Python扩展

kwa*_*ord 8 python windows 64-bit gcc mingw

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

我已成功使用VS2008为此平台编译了相关扩展.我也用mingw32(用32位python)编译它.我希望两个版本都使用GCC.

我使用Cygwin安装了mingw64-x86_64-w64 GCC 4.5.1工具集,并说服Python使用它们.但是,链接到python本身失败了.

所以我选择了pexports 0.44,用它来转储python26.def文件并创建libpython26.a.

现在,正如在这个问题中,我从Python获得的唯一链接错误是关于__imp_py_InitModule4.浏览def文件,我看到一个Py_InitModule4_64符号.

有任何想法吗?

Syl*_*sne 3

Python 中有一种机制可以防止将模块链接到错误版本的库。当为 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
Run Code Online (Sandbox Code Playgroud)

因此,如果您收到此错误,则意味着您的 Python 库或 Python 模块是针对 32 位架构编译的,而另一个是针对 64 位架构编译的。