问题
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:
- Create a project and add the source file.
- Go to the project properties, and do the following changes(Make sure to change the architecture to X64):
- Under C/C++ General, add the following directory to the field ADDITIONAL INCLUDE DIRECTORIES: C:\Program Files\MATLAB\\extern\include
- Under C/C++ Precompiled Headers, select "Not Using Precompiled Headers".
- Under Linker General, add the directory to the field ADDITIONAL LIBRARY DIRECTORIES: C:\Program Files\MATLAB\\extern\lib\win64\microsoft
- 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; Under Linker Input, add the following names to the field marked ADDITIONAL DEPENDENCIES: libmat.lib
libMatlabEngine.lib
libMatlabDataArray.libMake sure that the following directory is in the Windows system environment PATH:
C:\Program Files\MATLAB\\bin\win64;
C:\Program Files\MATLAB\\extern\bin\win64Now, 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