0

i'm having a new problem here with loading dll's. i didn't have any problem loading dll's with ".so", ".dll" extensions. now i'm having some issue with dll's with ".a" extension. its a static library. below is my code

Security_dll = ctypes.cdll.LoadLibrary("./staticlibraryname.a")

btw, my os env is a linux open suse. the exact error message i get when i try to do this is :

File "module3.py", line 3, in <module>
Security_dll = ctypes.cdll.LoadLibrary("./libSecurityProductionStaticlib.a")
File "/usr/lib64/python2.7/ctypes/__init__.py", line 440, in LoadLibrary
return self._dlltype(name)
File "/usr/lib64/python2.7/ctypes/__init__.py", line 362, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./libSecurityProductionStaticlib.a: invalid ELF header
kindall
  • 178,883
  • 35
  • 278
  • 309
BarathanR
  • 151
  • 1
  • 2
  • 8
  • did you build the library on the same platform/architecture ? – cmidi Dec 09 '16 at 03:58
  • Possible duplicate of [How to import static library in python?](http://stackoverflow.com/questions/19560594/how-to-import-static-library-in-python) – jdigital Dec 09 '16 at 03:59
  • the thing is i didnt build the library. its a project that im doing and the lib was given to me by other party. i have requested for the dll to be in dynamic format, but the request was refused. – BarathanR Dec 09 '16 at 04:02
  • Assuming this is a C library, you have to write a C program that calls the functions from the library, and statically link the program with the library. Then you can run the program from Python. Alternatively, create a dynamically linked wrapper around the static library. http://stackoverflow.com/questions/2649735/how-to-link-static-library-into-dynamic-library-in-gcc – DYZ Dec 09 '16 at 04:24

1 Answers1

6

You cannot load a static library into running code. Only dynamically linked libraries (.so and .dll) can be loaded. Static and dynamic libraries have different formats, properties, and purposes. Static libraries can be linked with other objects only at compile time, but not at run time. A dynamic library on Linux is essentially an ELF file without the main function. A static library is an archive of functions.

DYZ
  • 55,249
  • 10
  • 64
  • 93