Can I use the Matlab engine in a non-mex library?
이전 댓글 표시
The working situation is as follows:
- a library 'CPP_LIB' with ordinary C++ functions is compiled and built
- a mex-file is generated, it calls functions from 'CPP_LIB' so the mex is linked to 'CPP_LIB'
This works, but: now I want to be able to use the Matlab engine and call Matlab functions from within 'CPP_LIB'. That does not work, I get all sorts of compiler errors as soon as I even include <mex.hpp> and <mexAdapter.hpp>. Is there any way to do this?
댓글 수: 2
James Tursa
2023년 6월 23일
편집: James Tursa
2023년 6월 23일
It is not clear exactly what you are doing. What do you mean "... call MATLAB functions from within CPP_LIB ..."? How are you doing this calling exactly? If CPP_LIB is a normal C++ library, how is it trying to call mex functions? Is CPP_LIB the code that is invoking the MATLAB Engine?
The MATLAB Engine should be able to call mex routines the same as any other function. Just compile the mex routines normally and call them via engEvalString( ). But note that the architecture for this is that the MATLAB Engine is a separate process that does not share memory with your C++ code that is invoking the Engine ... meaning all variables must be deep copied back and forth, chewing up time and memory. If your variables are huge then this may not be the best approach.
Jeroen Boschma
2023년 6월 23일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!