Static library (.lib) for Python project

Is it possible to import modules from a .lib library into a Python program (as simple as a DLL)?

+7
python dll static-libraries
source share
4 answers

Theoretically, yes; probably not in practice - and certainly not as simple as a DLL. Static libraries are, in fact, only collections of object files, and they need a full linker to correctly resolve all move links that they may contain. You may be able to take your static library and simply link its contents to create a shared library, but this would require that the static library be built as position-independent code (PIC), which is not guaranteed. Theoretically, there is no reason why the work that the full linker will do to link the library cannot be done at run time, but in practice there is no ready-made code for this. Your best real option is probably for tracking the source or general version of the library.

+3
source share

Unfortunately not. Dynamic link libraries are required for loading at runtime.

+2
source share

Do you have access to the source code? Or at least a header file? If so, then you can either create a shared library or a Python extension that links to the library. Since you mentioned a DLL, I assume that you are running on Windows. This tutorial may be helpful.

0
source share

Do you have a static library or do you have a .lib file and is it supposed to be a static library? On Windows, the .lib library can be an import library or a static library. An import library is created along with a DLL with the same name (for example, kernel32.dll and kernel32.lib). It is used during the connection to populate the import address table of the executable file. The static library contains code that will be copied to the executable file during the connection.

If you have access to the compiler, another option might be to create an extension module that uses a static library. See Python docs for more details.

0
source share

All Articles