2

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.

Hüftl
  • 211
  • 2
  • 12
  • 1
    Check out this question-- http://stackoverflow.com/questions/1153577/integrate-python-and-c – g-217 Sep 23 '16 at 11:26
  • this answer helps a bit, but the answer provided is 7 years old, so maybe it is a bit outdated – Hüftl Sep 23 '16 at 13:54
  • How large is the library? `ctypes` is reasonably easy to use and is builtin, but it can get a little repetitive if you have to wrap many functions. – 101 Sep 25 '16 at 23:51
  • The library is pretty large. But I finally managed to import and access it with ctypes. – Hüftl Sep 26 '16 at 08:04

1 Answers1

1

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.

Hüftl
  • 211
  • 2
  • 12