我正在尝试使用 mingw-x64 在 Windows7(64 位)上为 python 编译 C 库。这一切都像 32 位版本的魅力一样。
我曾经用 gcc -shared -IC:\Python27\include -LC:\Python27\libs myModule.c -lpython27 -o myModule.pyd 编译我的库
它适用于 32 位版本。相同的过程适用于 64 位 linux。但是在 64 位 windows7 上(使用 64 位 x86_64-w64-mingw32 和 64 位 python 2.7.5)我有一个问题:
C:\Users\sergej\AppData\Local\Temp\cci8TbXw.o:myModule.c:(.text+0x267):
undefined reference to `__imp_Py_InitModule4'
collect2: ld returned 1 exit status
我检查了 C:/Python27/libs/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
我目前不知道该怎么做。有什么建议吗?C 代码在这里不是问题。我对来自
http://csl.name/C-functions-from-Python/
的示例有同样的问题
注意 - 本示例中第 26 行的错字:应该是 VARARGS
是的 - 我确实发现(类似于How can I build my C extensions with MinGW-w64 in Python? question )我可以通过将 -DMS_WIN64 添加到 gcc 行来编译这个简单的例子,但我仍然在我的真实中遇到类似的错误程序(建议还有更多)
undefined reference to `__imp_PyArg_ParseTuple'
undefined reference to `__imp_Py_BuildValue'
undefined reference to `__imp_Py_InitModule4_64'