python_x64 + C库与Windows7的Py_InitModule4 mingw_x64编译 [英] python_x64 + C library compiled with mingw_x64 on Windows7 Py_InitModule4

查看:1398
本文介绍了python_x64 + C库与Windows7的Py_InitModule4 mingw_x64编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译C库为Python使用的MinGW-64的Windows7(64位)。
它的所有工作就像32位版本的魅力。

我用来编译我的库
GCC -shared -IC:\\ Python27 \\包括-LC:\\ Python27 \\库mymodule.c的-lpython27 -o myModule.pyd

,并将其与32位版本的工作。同样的过程正在与64位Linux。
但在64位的windows7(使用64位的x86_64-W64-的mingw32和64位蟒蛇2.7.5)我有一个问题:

  C:\\用户\\谢尔盖\\应用程序数据\\本地的\\ Temp \\ cci8TbXw.o:mymodule.c的文字:( + 0x267):
未定义的引用`__imp_Py_InitModule4
collect2:劳工处返回1退出状态

我检查C:/Python27/libs/modsupport.h,它已经包含

 #如果SIZEOF_SIZE_T!= SIZEOF_INT
/ *在64位系统,重命名Py_InitModule4让2.4
   模块不能得到加载到2.5间preTER * /
#定义Py_InitModule4 Py_InitModule4_64
#万一

我目前的想法做什么。任何建议?
在C code是不是这里的问题。我有一个例子来自同样的问题
http://csl.name/C-functions-from-Python/

注 - 错字在第26行下面的例子:应该是VARARGS

和是 - 我没有发现(类似于<一个href=\"http://stackoverflow.com/questions/11182765/how-can-i-build-my-c-extensions-with-mingw-w64-in-python\">How我可以在Python的MinGW-W64建立我的C扩展?问题),我可以通过添加-DMS_WIN64到GCC编译行这个简单的例子,但我仍然在我的真正的程序得到了类似的错误(这表明有更多的它)

 未定义的参考`__imp_PyArg_ParseTuple
未定义的引用`__imp_Py_BuildValue
未定义的引用`__imp_Py_InitModule4_64


解决方案

抄袭为了注释的答案,从未答复的滤镜移除了这个问题:


  

我不想回答我的问题,但...添加-DMS_WIN64其实是不够的。剩下的问题是由于GCC参数(出于某种原因-lpython27应该向右走-o myModule.pyd之前),这是不正确的顺序在我的项目


〜每谢尔盖Srepfler 答案

I'm trying to compile C library for python on Windows7 (64-bit) using mingw-x64. It all worked like a charm with 32-bit versions.

I used to compile my library with gcc -shared -IC:\Python27\include -LC:\Python27\libs myModule.c -lpython27 -o myModule.pyd

and it worked with 32-bit versions. The same procedure is working with 64-bit linux. But on 64-bit windows7 (using 64-bit x86_64-w64-mingw32 and 64-bit python 2.7.5) I have a problem:

C:\Users\sergej\AppData\Local\Temp\cci8TbXw.o:myModule.c:(.text+0x267): 
undefined reference to `__imp_Py_InitModule4'
collect2: ld returned 1 exit status

I checked C:/Python27/libs/modsupport.h and it already contains

#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

I'm currently out of ideas what to do. Any suggestion? The C code is not an issue here. I have the same problem with example from http://csl.name/C-functions-from-Python/
Note - typo in line 26 in this example: should be VARARGS

And yes - I did found (similar to How can I build my C extensions with MinGW-w64 in Python? question ) that I can compile this trivial example by adding -DMS_WIN64 to gcc line, but I still got the similar errors in my real program (suggesting there is more to it)

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

解决方案

Copying the answer from the comments in order to remove this question from the "Unanswered" filter:

I hate to answer my own questions, but... adding -DMS_WIN64 is actually enough. Remaining problems were due to gcc parameters ( for some reason -lpython27 should go right before -o myModule.pyd), which were not in correct order in my project

~ answer per Sergej Srepfler

这篇关于python_x64 + C库与Windows7的Py_InitModule4 mingw_x64编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆