I am trying to call c-functions from Python using ctypes.
I have three c files, two with drivers(usb-1024LS.c and pmd.c) for a USB device and one with some functions(myTest_1024LS.c) to test the drivers. The driver c-files are using libusb. When I try running my script it seems like the compiler doesn't find the libusb. I get the error:
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /path-to-folder/usb1024LS_with_py/pmd.so: undefined symbol: usb_get_driver_np
usb_get_driver_np is a function in libusb.
My Python script:
import ctypes
pmd = ctypes.CDLL('/home/oysmith/NetBeansProjects/MCCDAQ/usb1024LS_with_py/pmd.so');
usb1024LS = ctypes.CDLL('/home/oysmith/NetBeansProjects/MCCDAQ/usb1024LS_with_py/usb-1024LS.so');
testFunc = ctypes.CDLL('/home/oysmith/NetBeansProjects/MCCDAQ/usb1024LS_with_py/myTest_1024LS.so');
# declare the function we use
testFunc.writeByte.argtypes = (ctypes.c_void_p,)
testFunc.writeByte.restype = ctypes.c_void_p
testFunc.findInterface.argtypes = (ctypes.c_void_p,)
testFunc.findInterface.restype = ctypes.c_void_p
pmd.PMD_GetInputReport.argtypes = (ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_int,)
pmd.PMD_GetInputReport.restype = ctypes.c_char_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_int, ctypes.c_int
#call C function
testFunc.findInterface()
Where findInterface call a function from pmd.c and the function in pmd.c call a function in libusb.
I am new to calling c functions from Python, so I need all the help I can get! Thanks!