Can I use the Matlab engine in a non-mex library?
Mostra commenti meno recenti
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 Commenti
James Tursa
il 23 Giu 2023
Modificato: James Tursa
il 23 Giu 2023
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
il 23 Giu 2023
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su C Shared Library Integration in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!