Error when calling startMATLAB() from C++

I wanted to try the Call Function with Name/Value Arguments example from https://de.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-c-1.html
I set the paths according to https://de.mathworks.com/matlabcentral/answers/406574-how-can-i-compile-a-c-program-that-uses-matlab-engine-c-api-in-visual-studio-2017 but the libMatlabEngine.dll and libMatlabDataArray.dll could still not be found. Because of that I copied them to the .dll files I am already using in the C++ project. Now this error did not occur anymore. (I do not know whether this affects the error somehow, so I am saying it.)
When I execute the program now, I get an unhandled exception during the execution of
std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB();
more exactly:
Error.PNG
Do you have any idea how to fix this?

Respuestas (2)

飞 罗
飞 罗 el 10 de Jun. de 2022

0 votos

Hi @fee,are you have overcme this error? if you are ,could you tell me how to do it?
my email LUOFEI1310783372@163.com
LUO,
Melvin
Melvin el 28 de Jun. de 2022

0 votos

For me the solution was missing one additional step; In Visual Studio project linker->General tab I needed to switch "Use library dependency inputs" to yes.

1 comentario

Melvin
Melvin el 7 de Jul. de 2022
In further testing, the linker switch isn't an absolute solution. I could run in x64 debug OK but failed in release. I found I could get both debug & release to run by adjusting the PATH variable such that the <MATLAB ROOT>/extern/bin/win64 path appeared first followed by <MATLAB ROOT>/bin/win64. Order was important. Reversing that path order would cause the startup to fail. This was a x64 MFC GUI that started the Matlab engine as part of the CMainFrame using the async start and checking the future on a timer to enable remaining GUI functionality.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

fee
el 25 de Jul. de 2019

Comentada:

el 7 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by