我正在尝试使用 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/ http://csl.name/C-functions-from-Python/
注意 - 本例中第 26 行的拼写错误:应该是 VARARGS
是的 - 我确实发现了(类似于如何在 Python 中使用 MinGW-w64 构建我的 C 扩展? https://stackoverflow.com/questions/11182765/how-can-i-build-my-c-extensions-with-mingw-w64-in-python问题)我可以通过将 -DMS_WIN64 添加到 gcc 行来编译这个简单的示例,但我在实际程序中仍然遇到类似的错误(表明还有更多错误)
undefined reference to `__imp_PyArg_ParseTuple'
undefined reference to `__imp_Py_BuildValue'
undefined reference to `__imp_Py_InitModule4_64'