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:

Do you have any idea how to fix this?
回答(2 个)
飞 罗
2022-6-10
0 个投票
my email LUOFEI1310783372@163.com
LUO,
Melvin
2022-6-28
0 个投票
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 个评论
Melvin
2022-7-7
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Call MATLAB from C++ 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!