Calling mex Function from Python extension

44 ビュー (過去 30 日間)
Jim Glidewell
Jim Glidewell 2016 年 9 月 21 日
コメント済み: Bo Li 2016 年 9 月 23 日
I am trying to write a Python extension program to call a MATLAB mex function. What I want to do is to have my program directly call the function mexFunction(...) with my own mxArray parameters, etc.
When I run the program in Python I get a DLL load error. After some experimenting I found that if I comment out the include statement for mex.h the program loads fine, but as soon as I include mex.h I get the DLL load error again.
My theory is that there is a DLL conflict because the program as been declared to be both a Python DLL and a MATLAB DLL and the system gets confused. I tried going into the mex.h file and commenting out the DLL_EXPORT command hoping I could trick it, but that didn't help. So now I'm thinking that maybe it is still getting declared as a DLL in the MATLAB lib files, but that is just a guess.
The bottom line is this. I basically want to be able to call a mex function from my own program similar to how MATLAB would call the function, passing in the mxArray variables and other parameters. I assume they are doing something like a call to LoadLibrary followed by GetProcAddress. How can I do something similar without it thinking that this is a DLL?
Thank you.

回答 (1 件)

Bo Li
Bo Li 2016 年 9 月 22 日
How do you want to invoke this MEX file? From inside MATLAB or in Python? You can use mxArray in Python without using MEX. Or you can use Python Interface to invoke the Python extension directly from MATLAB:
  2 件のコメント
Bo Li
Bo Li 2016 年 9 月 23 日
Maybe you can add the matlabroot/bin/win64 folder into the system PATH and see how it works.


Community Treasure Hunt

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

Start Hunting!

Translated by