Calling mex Function from Python extension
20 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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
2016-9-23
Maybe you can add the matlabroot/bin/win64 folder into the system PATH and see how it works.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!