Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import static library in python? [duplicate]

I have a static library(liba.a) and i want to use it in python

but import can only import dynamic library in python

how to import static library in python??

like image 994
blueman010112 Avatar asked Oct 24 '13 08:10

blueman010112


People also ask

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.

How will you create a static library from object files?

Static libraries are created using some type of archiving software, such as ar. ar takes one or more object files (that end in .o), zips them up, and generates an archive file (ends in . a) — This is our “static library”. Now that we have the object file(s), we can archive them and make a static library using ar.


1 Answers

You can't do this. You have two options:

  1. Recompile the library as a shared library. Then use ctypes to call methods from the dynamically-loaded shared library.

  2. Build a Python Extension exposing a Python interface to the shared library.

like image 165
Jonathon Reinhart Avatar answered Sep 30 '22 14:09

Jonathon Reinhart