在Windows7 Py_InitModule4上使用mingw_x64编译的python_x64 + C库

我正在尝试使用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

是的 – 我确实找到了(类似于我如何用Python中的MinGW-w64构建我的C扩展?问题)我可以通过将-DMS_WIN64添加到gcc行来编译这个简单的例子,但我仍然在我的真实中遇到了类似的错误程序(建议还有更多)

 undefined reference to `__imp_PyArg_ParseTuple' undefined reference to `__imp_Py_BuildValue' undefined reference to `__imp_Py_InitModule4_64' 

复制评论中的答案,以便从“未答复”filter中删除此问题:

我不想回答我自己的问题,但是……添加-DMS_WIN64实际上已经足够了。 剩下的问题是由于gcc参数(由于某种原因-lpython27应该在-o myModule.pyd之前发生),这在我的项目中没有正确的顺序

〜每个Sergej Srepfler回答