mingw32/bin/ld.exe: cannot find -lpython"

Viewed 874

Excuse my newbiness. I have been trying to extend python with c for days now. there are lots of methods and none of them are Windows-friendly. Currently I am trying to follow this SWIG tutorial(buttom of the page).https://en.wikibooks.org/wiki/Python_Programming/Extending_with_C#Using_SWIG

I've reached the last step where I should link everything to python, but when I write the command

 `gcc -shared hellomodule.o hello_wrap.o -o _hello.so -lpython`

I get this error "c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpython"

I've tried:

  • adding python as an environmental variable
  • copying python address to the link command as follows

gcc -shared hellomodule.o hello_wrap.o -o _hello.so -lC:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32

any help would be REALLY appreciated

1 Answers

It's looking for libpython.so, which you won't find on Windows. In general, Python extensions on Windows must be built with the same compiler that built Python, so that the runtime libraries match up, and that's almost always Visual Studio. Check here for details:

https://docs.python.org/3/extending/windows.html

If you have a Mingw build of Python, then you're going in the right direction. If not, then you'll need Visual Studio.

Related