I have a c program(.c file). I am converting that to a shared object(.so). How can i call and run the shared object from my python code? If possible, please suggest me a list of libraries that can help me to do this task.
If you want to call functions inside a shared object, the the standard module ctypes is what you are after. No need for any external libraries.
Load a library:
from ctypes import *
# either
libc = cdll.LoadLibrary("libc.so.6")
# or
libc = CDLL("libc.so.6")
Then call a function from the library, the same as calling a Python function:
print(libc.time(None))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With