1

I have some .lib(c++ static library) files and I need to use them in my python program.

I know I should use wrapper but I don't know how and have no idea what is that. I searched and found that ctypes python library uses .dll to load the library and as I have .lib files I don't know how can I use them in python.

1 Answers1

-1

I recommend you to write a Python extension based on your C++ code, but if that's too complicated, you can use ctypes but then your static library will need to be a shared library instead.

Keep in mind that for writing Python bindings you have several options, like cffi, PyBind11, Shiboken, etc.

cmaureir
  • 285
  • 2
  • 8
  • how can i use static library as shared library? – Mohammad Ali Jan 31 '19 at 09:05
  • @MohammadAli You will have to link the static library into a shared object (Posix platforms) or DLL (Windows). You will need a linker for that. – Martin Bonner supports Monica Jan 31 '19 at 09:15
  • How can I link static library into DLL? I couldn't find anything @MartinBonner – Mohammad Ali Jan 31 '19 at 09:31
  • @MohammadAli That's odd. I found lots of hits when I googled "link static library into dll". You will need to understand the difference between a dll and a static library, and how the tools work. If you have no experience working with non-python code that's going to be a learning experience. Comments are not the right forum to discuss this (and questions on SO are probably not either - you need the good book list. – Martin Bonner supports Monica Jan 31 '19 at 13:01