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

Ser*_*ler 9 c python gcc windows-7-x64 mingw-w64

我正在尝试使用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
Run Code Online (Sandbox Code Playgroud)

我检查了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
Run Code Online (Sandbox Code Playgroud)

我目前不知道该怎么做.有什么建议吗?这里的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'
Run Code Online (Sandbox Code Playgroud)

Dre*_*awn 9

复制评论中的答案,以便从"未答复"过滤器中删除此问题:

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

〜每个Sergej Srepfler回答