Static library (.lib) to Python project
is it possible 开发者_运维技巧to import modules from .lib library to Python program (as simple as .dll)?
In theory, yes; in practice, probably not -- and certainly not as simply as a DLL. Static libraries are essentially just collections of object files, and need a full linker to correctly resolve all relocation references they may contain. It might be possible to take your static library and simply link its contents to form a shared library, but that would require that the static library had been built as position independent code (PIC), which is not guaranteed. In theory there's no reason the work a full linker would do to link the library couldn't be done at runtime, but in practice there's no off-the-shelf code for doing so. Your best real option is probably to track down the source or a shared version of the library.
Unfortunately, no. Dynamic Link Libraries are required for runtime loading.
Do you have access to the source code? Or at least a header file? If you do, then you could either create a shared library or a Python extension which links to the library. Since you mentioned DLLs, I'll assume you're working on Windows. This tutorial may be useful.
Do you have a static library or do you have a .lib file and are assuming that it is a static library? On Windows, a .lib library can be an import library or a static library. An import library is created alongside the dll of the same name (eg kernel32.dll and kernel32.lib). It is used at link time to populate the import address table of the executable. A static library contains code that will be copied into the executable at link time.
If you have access to a compiler, another option may be to create an extension module that makes use of the static library. For more details see the Python docs
精彩评论