Matlab runtime initialization from Python using ctypes

조회 수: 6 (최근 30일)
Alexandros Kessanopoulos
Alexandros Kessanopoulos 2019년 7월 24일
댓글: Alexandros Kessanopoulos 2020년 4월 8일
Hello,
I am trying to use a c dll that is created with Matlab Compiler SDK from python using the ctypes module.
The first step is to call the mclInitializeApplication function but that fails.
Here is a python snippet:
import ctypes
mclbase_dll = ctypes.cdll.LoadLibrary('mclbase.dll')
mclInitializeApplication = mclbase_dll.mclInitializeApplication
clInitializeApplication.argtypes = [ctypes.POINTER(ctypes.c_char_p),ctypes.c_size_t]
clInitializeApplication.restype = ctypes.c_bool
ptr = ctypes.c_char_p()
b = mclInitializeApplication(ctypes.byref(ptr),0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [WinError -529697949] Windows Error 0xe06d7363
Is this possible at all to use matlab runtime from python using ctypes or I am doing something wrong here?
Thank you
  댓글 수: 2
Shubham Kashyap
Shubham Kashyap 2020년 4월 8일
The genearted .dll from C/C++ will not work with python. But Matlab compiler SDK have a python target. I recommend using that to call python.
>>web(fullfile(docroot, 'compiler_sdk/python_packages.html'))
The generated .dll don't have native C interface. For this to work you need to create a wrapper around the actual .dll. Refer here.
Alexandros Kessanopoulos
Alexandros Kessanopoulos 2020년 4월 8일
Thanks for the comment. I have done this procedure and created the wrapper so from python I intend to call the wrapper function/dll which has a native api and not the matlab compiler sdk generated one.
If you notice my snippet above the python call (using ctypes) fails at the application initialization itself where function's api is native C and not at the function call.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by