Issu using startMATLAB in C++ with “MatlabEngine.hpp” in r2017b

Deadly 提交于 2019-12-24 03:06:01

问题


In its new version 2017b, Matlab has released a new MATLAB Engine API for C++: https://fr.mathworks.com/help/matlab/calling-matlab-engine-from-cpp-programs.html

When I try to use this API, (only to start Matlab at the beginning !!), I have an issue using :

std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB();

The compilation is ok, but at the execution :

Here is the call stack:

matlab::engine::initSession --> matlab::engine::startMATLAB --> matlab::engine::startMATLABAsync --> engine_create_session

Now, I use a different way to do my job, but I don't want to let an issue without a solution. Can someone spot the problem with this API?

My configuration :

  • Matlab 2017b
  • Visual Studio 2017
  • Windows 10

回答1:


Just a few days back, I had the same issue: here

So, I had raised a ticket in MATLAB for technical support. And they suggested to build the project in the following manner which works for me:

  1. Create a project and add the source file.
  2. Go to the project properties, and do the following changes(Make sure to change the architecture to X64):
  3. Under C/C++ General, add the following directory to the field ADDITIONAL INCLUDE DIRECTORIES: C:\Program Files\MATLAB\\extern\include
  4. Under C/C++ Precompiled Headers, select "Not Using Precompiled Headers".
  5. Under Linker General, add the directory to the field ADDITIONAL LIBRARY DIRECTORIES: C:\Program Files\MATLAB\\extern\lib\win64\microsoft
  6. e. Under Configuration Properties ->Debugging Add the following 2 Target paths in the Environment: PATH=C:\Program Files\MATLAB\\bin\win64;
    PATH=C:\Program Files\MATLAB\\extern\bin\win64;
  7. Under Linker Input, add the following names to the field marked ADDITIONAL DEPENDENCIES: libmat.lib
    libMatlabEngine.lib
    libMatlabDataArray.lib

  8. Make sure that the following directory is in the Windows system environment PATH:
    C:\Program Files\MATLAB\\bin\win64;
    C:\Program Files\MATLAB\\extern\bin\win64

  9. Now, build the project and run your application.




回答2:


Like in the comment, I solved the issue by upgrading Matlab from R2017b to R2018b!



来源:https://stackoverflow.com/questions/47693078/issu-using-startmatlab-in-c-with-matlabengine-hpp-in-r2017b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!