Problem with Matlab API Data in c++ project (QtCreator)

5 ビュー (過去 30 日間)
Cristian Ramírez
Cristian Ramírez 2022 年 2 月 16 日
編集済み: Divyanshu 2024 年 1 月 31 日
Hi,
I am having trouble trying to configure a project in qt creator (version 4.15.1 and 6.2.1 qt framework with MSVC 2019 64 bit compiler) using the matlab api C++. I have compiled a shared library using the Library compiler SDK from Matlab (R2021b). I also have previously succesfully configure the project to use the old version (Matlab API C), using mxarrays and mcl and mlx functions. The project works fine at this point.
I want to upgrade the code to use the modern version of the API for c++, because of some of its features (for example, using asynchronous calls to the library function).
I have added the following lines to my project file (qmake):
# MATLAB API
MATLAB_FOLDER = $$(MATLAB_RUNTIME_FOLDER)
LIBS += -L$$MATLAB_FOLDER/extern/lib/win64/microsoft -llibMatlabCppSharedLib -llibMatlabDataArray
INCLUDEPATH += $$MATLAB_FOLDER/extern/include
DEPENDPATH += $$MATLAB_FOLDER/extern/include
MATLAB_RUNTIME_FOLDER is a system variable where i indicate the path to the matlab runtime folder (version 9.11). I also copied the dlls into my project where the .exe is created. From /v911/runtime/win64 i took libMatlabCppSharedLib9_11.dll and from /v911/extern/bin/win64 libMatlabDataArray.dll.
The initialization of the aplication and the library seems to work fine:
namespace mc = matlab::cpplib;
namespace md = matlab::data;
std::vector<std::u16string> options = { u"-nojvm" };
auto matlab_application = mc::initMATLABApplication(mc::MATLABApplicationMode::IN_PROCESS, options);
auto lib = mc::initMATLABLibrary(matlab_application, u"test.ctf");
The problem lies when I try to declare a factory variable:
md::ArrayFactory factory;
My application launches an exception and i do not know why. Maybe I lack another dependancy ?
  2 件のコメント
Benjamin Thompson
Benjamin Thompson 2022 年 2 月 16 日
Can you post the text or an image of the exception?
Cristian Ramírez
Cristian Ramírez 2022 年 2 月 17 日

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

回答 (1 件)

Divyanshu
Divyanshu 2024 年 1 月 31 日
編集済み: Divyanshu 2024 年 1 月 31 日
Hi Cristian,
Please go through the following pointers:
  • Ensure that the file 'C:\Program Files\MATLAB\MATLAB Runtime\v911\runtime\win64' is added to the path.
  • Launch MATLAB in your system.
  • Now build the application with the following command:
>>mbuild main.cpp
  • Execute the application using the command:
!main.exe
Regards,
Divyanshu

カテゴリ

Help Center および File ExchangeDeploy to C++ Applications Using MATLAB Data API (C++11) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by