for C++: Can I use MATLAB ENGINE (matlab::engine) with CTF (matlab::cpplib), for matlab 2019b?

조회 수: 4 (최근 30일)
it seems to be that
#include "MatlabEngine.hpp"
and
#include "MatlabCppSharedLib.hpp"
cannot co-exist?
If I include matlab engine first, I cannot use ctf file. If I include cpp shared lib first, I cannot use engine.
Is there any solution to this issue for matlab 2019b?
The reason/driving factor is behind this need -- I want to be able to switch (only once at program start up) between using matlab engine or ctf based on user input. Any other suggestion or alternative ways to achieve this goal will be greatly appreciated.

채택된 답변

Harshit Gupta
Harshit Gupta 2022년 4월 26일
It is my understanding that you are not able to use #include "MatlabEngine.hpp" and #include "MatlabCppSharedLib.hpp" within the same “cpp” file.
As a workaround to this issue, I would suggest you create two separate "cpp" function files, one that exclusively includes "MatlabEngine.hpp", and another that exclusively includes "MatlabCppSharedLib.hpp".
You can then have one or the other called in the main function based on the user's input.
  댓글 수: 2
Yifan Lin
Yifan Lin 2022년 4월 26일
Thanks! I was hoping to avoid this alternative, since the feval calls are the same, I'd have to copy and paste same calling codes into two different "cpp" files and have to remember to update them separately. Unless there is some macro that can help with this separate maintainability issue?
Harshit Gupta
Harshit Gupta 2022년 4월 28일
Regarding using macros, the preprocessor only does one pass through everything, so I don't believe it’s possible.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by