ctypes를 사용하여 파이썬에서 c 함수를 호출하려고합니다.Python에서 C 함수 호출
USB 장치 용 드라이버 (usb-1024LS.c 및 pmd.c)와 드라이버를 테스트하는 몇 가지 기능 (myTest_1024LS.c)이있는 두 개의 c 파일이 있습니다. 드라이버 c- 파일은 libusb를 사용하고 있습니다. 스크립트를 실행하려고하면 컴파일러가 libusb를 찾지 못하는 것처럼 보입니다. 오류 :
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는 libusb의 함수입니다.
내 파이썬 스크립트 : findInterface는 pmd.c에서 기능과 pmd.c에서 함수를 호출
이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()
libusb를의 함수를 호출합니다.
저는 파이썬에서 c 함수를 호출하는 것이 처음이므로, 제가 얻을 수있는 모든 도움이 필요합니다! 감사합니다.
python/프로그램을 실행중인 터미널에서 "ldd /path-to-folder/usb1024LS_with_py/pmd.so"를 실행하면 출력은 무엇입니까? 모든 의존성이 해결 되었습니까? –
다음과 같이 출력됩니다 : linux-vdso.so.1 => (0x00007fffcfe8b000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0693615000) /lib64/ld- linux-x86-64.so.2 (0x00007f0693bf7000) –