Can I use the Matlab engine in a non-mex library?
Afficher commentaires plus anciens
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 commentaires
James Tursa
le 23 Juin 2023
Modifié(e) : James Tursa
le 23 Juin 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
le 23 Juin 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur C Shared Library Integration dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!