Using the Matlab C++ Engine SDK to connect to matlab from within library built with the c++ clibgen workflow

3 ビュー (過去 30 日間)
Trevor
Trevor 2024 年 2 月 28 日
コメント済み: Michele 2025 年 2 月 24 日
Hello All,
I have a library written in c++ (dll on windows) that I use with the clib generation workflow to create a clib interface to the library.
This works good - but lacks some things (namely printing to the matlab console when running functions).
I started to use the matlab C++ Engine sdk inside the dll library. (using the matlab sdk headers). And I during testing - I am unable to connect to a shared matlab instance. it gives an error ("unable to connect to matlab session") when calling
auto matlabEngine = matlab::engine::connectMATLAB(u"MATLAB_27404");
Using the python engine sdk I can connect to the same instance just fine.
I suspect that it might be because I am trying to connect from within a dll that is bound to the matlab instance I am trying to connect to (via the clib interface).
Is there a known way to do this without some sort of proxy application etc?
Thanks in advance for any Tips/Help,
-Trevor
  1 件のコメント
Michele
Michele 2025 年 2 月 24 日
Hello Trevor,
I think I am having the same problem here (just got there the other way around, first using the matlab engine from a C++ application, which was working fine, then found this issue when building it into a dll and loading it with clib). Did you by any chance get to solve this? Or found a definite answer on whther this is possible at all or not? And if not, could you comment on any alternative approaches you have taken?
Thanks!

サインインしてコメントする。

回答 (1 件)

Divyanshu
Divyanshu 2024 年 3 月 5 日
Hi Trevor,
You can refer the following documentation which explains about how to call MATLAB from C++ and exchange the data between MATLAB and C++ programs:
Additionally, you can refer the following MATLAB Answer thread specifically for the issue of not being able to connect to existing shared MATLAB session:

カテゴリ

Help Center および File ExchangeCall MATLAB from C++ についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by