9

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'
2
  • 1
    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 Commented Sep 10, 2013 at 16:06
  • If you're game to recap the solution as your own answer, I'll delete my answer. (See meta.stackexchange.com/questions/90263/… for elaboration of why this is helpful.) Thanks! Commented Oct 10, 2013 at 5:02

1 Answer 1

9

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.