0

I compiled my Python code with Cython and I got a .pyd file and a .c file. Then I installed GCC and I typed gcc maido.c in my prompt.

I got 973 lines like:

C:\Users\loic\AppData\Local\Temp\ccde4A55.o:maido.c:(.text+*x*****): undefined reference to __imp_Py*****_******

And 3 last lines:

C:/Users/python/Anaconda3/Library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status

I did some research and I saw that it was a common issue. Yet I did not find a solution to fix it.

Do I have to install anything or to add a command in the prompt ?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Loïc Poncin
  • 511
  • 1
  • 11
  • 30
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – too honest for this site Jun 26 '17 at 18:42
  • @Olaf I already saw that post, I ask that question because I don't understand any of the answers they gave. I am a bit new the C world. – Loïc Poncin Jun 26 '17 at 18:45
  • And the best you could think of is ask another dup? If you don't understand an answer, do research about the subject. Chances are good you lack the basics. – too honest for this site Jun 26 '17 at 18:49
  • @Olaf I first saw that post because https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16/5260237#5260237 but I did not manage to solve my problem. I am aware of the other posts and my desire was not to bother the community or to be lazy. If it looks like it I am sorry, I have been working for days trying to translate my Python code with Cython and compile to use it as a module. That's why I have been asking few questions these last days. – Loïc Poncin Jun 26 '17 at 18:53
  • If you have a .pyd file then you're done - it's managed to compile the C file successfully. You don't need to compile it again yourself. You can `import` the pyd file in Python to use it – DavidW Jun 26 '17 at 21:07
  • @DavidW I did that but I got that message: `import maido` `ImportError: dynamic module does not define module export function (PyInit_maido)` So I thought that I could try to compile with GCC instead of Cython. – Loïc Poncin Jun 26 '17 at 21:10
  • That's your real problem then. Unfortunately you don't say how you built your Cython module. My best guess would be that you built in with Python2 but are trying to run it in Python3 (but that is a guess...) – DavidW Jun 26 '17 at 21:12
  • I made a `setup.py` file and I saved my `maido_python.py` file as `maido_cython.pyx`. I typed `python setup.py install` and then `python setup.py build_ext --inplace`. It worked, I got two files: `maido_cython.c` and `maido_cython.cp36-win_amd64.pyd`. Here is a link to my files (don't worry I uploaded them on my own Google account): https://drive.google.com/drive/folders/0B7P95aWmH4DUYllKQW9QZzMxSGM – Loïc Poncin Jun 26 '17 at 21:21
  • @DavidW And I use Python 3.5 with Anaconda 3 (64 bits). (sorry for the 2 comments I could not edit my last one) – Loïc Poncin Jun 26 '17 at 21:32

0 Answers0