1

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
4
  • did you build the library on the same platform/architecture ? Commented Dec 9, 2016 at 3:58
  • Possible duplicate of How to import static library in python? Commented Dec 9, 2016 at 3: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. Commented Dec 9, 2016 at 4: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. stackoverflow.com/questions/2649735/… Commented Dec 9, 2016 at 4:24

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

As I said, you cannot do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.