Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static library (.lib) to Python project

is it possible to import modules from .lib library to Python program (as simple as .dll)?

like image 301
CarolusPl Avatar asked Sep 08 '10 13:09

CarolusPl


People also ask

Is .LIB a static library?

Static Linking creates larger binary files, and need more space on disk and main memory. Examples of static libraries (libraries which are statically linked) are, . a files in Linux and . lib files in Windows.

Can python import static library?

You can't do this. You have two options: Recompile the library as a shared library. Then use ctypes to call methods from the dynamically-loaded shared library.

What is .LIB file in Python?

The Python Standard Library contains the exact syntax, semantics, and tokens of Python. It contains built-in modules that provide access to basic system functionality like I/O and some other core modules. Most of the Python Libraries are written in the C programming language.

What is the use of .LIB file?

LIB (lib.exe) creates standard libraries, import libraries, and export files you can use with LINK when building a program.


1 Answers

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.

like image 136
llasram Avatar answered Sep 24 '22 00:09

llasram