Hüftl
Hüftl

Reputation: 231

Building a python interface for a *.so

I want to make use of a C library, from which a shared object and the header files are available.

As the documentation of ctypes and Cython are very scarce and tutorials about those were for different usage, I need some help.

So, I don't know where to start here and which tool would be the easiest solution for a Python beginner like me.

Upvotes: 2

Views: 510

Answers (1)

Hüftl
Hüftl

Reputation: 231

I finally managed to import the library with ctypes. Cython didn't work out for me, and seemed to complex with the different files needed.

After getting an error like: undefined symbol: inflate, the accessing really worked out with importing the needed pcap lib from the system libs. I just didn't knew that it was needed. I found where it is with: find /usr/lib/ -name libpcap*

from ctypes import cdll

def main():
    libpcap = cdll.LoadLibrary('path/to/libpcap.so')
    lib = cdll.LoadLibrary('path/to/lib.so')
    lib.function_from_lib

if __name__ == "__main__":
    main()

So I hope, if anyone has this problem and comes from google, here is a solution which might help.

Upvotes: 1

Related Questions