我无法使用 matlab 2014a、Win7 64bit、64bit 从使用 VS2012 或 VS2013、英特尔编译器的 c++ 程序构建的启动 Matlab 引擎。我可以使用 Matlab 2013a 很好地启动引擎。如果我链接到 2014a,程序会抱怨 libmwmfl_scalar.dll 丢失并且无法启动。这是一个包含在 2013 中的 dll,但似乎不再包含在 2014a 中(无论是在程序中还是在编译器运行时分发中)。如果我链接到 2013a,它运行没有问题。为什么当我更新到 2014a 时它会坚持使用旧的 DLL?我已将所有包含、库、环境更改为 2014a,并在清理后重建。我的属性中没有明确引用 libmwmfl_scalar.dll 并将所有文件夹更改为 2014a。我没有链接到任何其他使用 Matlab 的东西。这个 dll 没有
这些设置与另一篇文章(在 Visual Studio 中直接调用 MATLAB(多线程))中的此属性表中一样,它提供了一些相关的上下文。
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<LocalDebuggerEnvironment>PATH=C:\Program Files\MATLAB\R2014a\bin\win64;%PATH%$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>C:\Program Files\MATLAB\R2014a\extern\include;C:\Program Files\MATLAB\R2014a\extern\include\win64</AdditionalIncludeDirectories>
<PreprocessorDefinitions>IBMPC</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\Program Files\MATLAB\R2014a\extern\lib\win64\microsoft</AdditionalLibraryDirectories>
<AdditionalDependencies>libmx.lib;libmex.lib;libmat.lib;libeng.lib;mclmcrrt.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
Ben - 不,我没有使用 Mex 文件。这是调用 Matlab 的代码
void mlsurfaceplot(std::vector<std::vector<double>> surface,std::vector<double> Xdat,std::vector<double> Ydat)
{
Engine *ep;
mxArray *Xmx = NULL, *result = NULL;
mxArray *Ymx=NULL;
mxArray *Zmx=NULL;
char buffer[BUFSIZE+1];
// double tim[10] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
//Have to stick vectors in arrays for Matlab xfer
double *xArray; //Declare pointer to type of array
xArray = new double[Xdat.size()]; //use 'new' to create array of size x
double *yArray; //Declare pointer to type of array
yArray = new double[Ydat.size()]; //use 'new' to create array of size x
double *zArray; //Declare pointer to type of array
zArray = new double[Xdat.size()*Ydat.size()]; //use 'new' to create array of size x
for (int j = 0; j < Xdat.size(); j++)
{
xArray[j]=Xdat[j];
}
for (int j = 0; j < Ydat.size(); j++)
{
yArray[j]=Ydat[j];
}
for (int i = 0; i < Xdat.size(); i++)
{
for (int j = 0; j < Ydat.size(); j++)
{
zArray[i+Xdat.size()*j]=surface[i][j];
}
}
/*
* Call engOpen with a NULL string. This starts a MATLAB process
* on the current host using the command "matlab".
*/
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
//return EXIT_FAILURE;
}
/*
* Create a variable for our data
*/
using namespace std;
Xmx = mxCreateDoubleMatrix(1,Xdat.size(), mxREAL);
Ymx = mxCreateDoubleMatrix(1,Ydat.size(), mxREAL);
Zmx = mxCreateDoubleMatrix(Xdat.size(), Ydat.size(), mxREAL);
//T = mxCreateDoubleMatrix(3, 2, mxREAL);
//memcpy((void *)mxGetPr(T), (void *)tim, sizeof(tim));
memcpy(mxGetPr(Xmx), &xArray[0], sizeof(double)*Xdat.size());
memcpy(mxGetPr(Ymx), &yArray[0], sizeof(double)*Ydat.size());
memcpy(mxGetPr(Zmx), &zArray[0], sizeof(double)*Xdat.size()*Ydat.size());
//std::cout<<T[0]<<std::endl;
/*
* Place the variable T into the MATLAB workspace
*/
engPutVariable(ep, "X", Xmx); engPutVariable(ep, "Y", Ymx);
engPutVariable(ep, "Z", Zmx);
std::cout<<*mxGetPr(Xmx)<<std::endl;
std::cout<<*mxGetPr(Ymx)<<std::endl;
std::cout<<*mxGetPr(Zmx)<<std::endl;
std::cout<<*(mxGetPr(Xmx)+1)<<std::endl;
std::cout<<*(mxGetPr(Ymx)+1)<<std::endl;
std::cout<<*(mxGetPr(Zmx)+1)<<std::endl;
/*
* Plot the result
*/
engEvalString(ep, "surf(X,Y,Z')");
engEvalString(ep, "ylabel('Log Spot/Strike')");
engEvalString(ep, "xlabel('Expiry (Years)')");
engEvalString(ep, "zlabel('Black 76 Vol')");
engEvalString(ep, "alpha(0.5)");
engEvalString(ep,"saveas(figure1,'c:\\users\\Rodney\\Documents\\filename2.jpg'),'jpg'");
/*
* use fgetc() to make sure that we pause long enough to be
* able to see the plot
*/
printf("Hit return to continue\n\n");
fgetc(stdin);
int jj;
cin>>jj;
/*
* We're done for Part I! Free memory, close MATLAB figure.
*/
printf("Done for Part I.\n");
mxDestroyArray(Xmx);
mxDestroyArray(Ymx);
mxDestroyArray(Zmx);
// mxDestroyArray(T);
engEvalString(ep, "close;");
// return 0;
}
这是我的路径,同时存在 2013a 和 2014a。我也试过删除 2013a,重新启动 VS,重建,但它仍然在寻找旧的 DLL。
C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\mpirt;C:\Program文件 (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\Program Files (x86) \Intel\icsxe\2013.1.046\bin;C:\Program Files\MATLAB\R2014a\bin;C:\Program Files\MATLAB\R2014a\bin\win64;C:\Users\Rodney\Anaconda\Lib\site- packages\PyQt4;C:\Program Files (x86)\Intel\Trace Analyzer and Collector\8.1.4.045\bin;C:\Program Files (x86)\Intel\MPI\4.1.3.045\em64t\bin;C:\ Program Files (x86)\Intel\MPI\4.1.3.045\ia32\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\mpirt;C:\Program Files (x86)\ Common Files\Intel\Shared Libraries\redist\ia32\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\PROGRA~2 \Intel\MPI\411~1.036\em64t\bin;C:\PROGRA~2\Intel\COMPOS~1\bin\intel64;C:\PROGRA~2\Intel\COMPOS~1\redist\intel64\compiler;C :\PROGRA~2\MICROS;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files ( x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Common Files\Seagate\SnapAPI\;C:\Program Files\MATLAB\R2014a\runtime\win64; C:\Program Files\MATLAB\R2014a\polyspace\bin;\win64;C:\Program Files\MATLAB\MATLAB Compiler Runtime\v83\runtime\win64;C:\Program Files\MATLAB\R2013a\runtime\win64;C :\Program Files\MATLAB\R2013a\bin;C:\Program Files\MATLAB\R2013a\bin\win64;C:\Users\Rodney\Anaconda;C:\Users\Rodney\Anaconda\Scripts;C:\PROGRA~2\Gambit-C\v4.7.2\bin;C:\Users\Rodney\AppData\Roaming\cabal\bin; C:\Program Files (x86)\Intel\Trace Analyzer and Collector\8.1.4.045\dll\impi64;C:\Program Files (x86)\Intel\Trace Analyzer and Collector\8.1.3.037\dll\impi64;C: \Program Files\smartmontools\bin;C:\ghc-7.6.3\bin;C:\Program Files (x86)\WinAnt\bin;c:\windows\system32;C:\Users\Rodney\AppData\Roaming\ cabal\bin\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\\Program Files (x86)\WinAnt\bin;c:\windows\system32;C:\Users\Rodney\AppData\Roaming\cabal\bin\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\; C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\\Program Files (x86)\WinAnt\bin;c:\windows\system32;C:\Users\Rodney\AppData\Roaming\cabal\bin\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\; C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
更新:我尝试在 VS2013 中创建一个新的解决方案和项目,它适用于 ML2014a。所以它一定是影响我现有项目或解决方案的东西,但很难追踪,因为我对 Matlab 没有间接依赖关系,并且已将所有路径设置为 2014a 版本。我的程序使用外部库 Boost、Intel MKL、Armadillo、Eigen、Quantlib。完全被难住了。
更新 2: 我已经检查并且我的程序在与 Visual Studio 环境之外的 2014a 链接时运行。当我尝试从 VS 运行它以进行调试时(“调试/开始调试”或“调试/不调试启动”),由于缺少 libmwmfl_scalar.dll,它不会运行。因此,出于某种原因,VS 坚持在程序本身不使用它时运行程序。