0

I can't start the Matlab Engine using matlab 2014a, Win7 64bit, 64bit build from a c++ program using VS2012 or VS2013, Intel compiler. I can start the engine fine using Matlab 2013a. If I link against 2014a the program complains libmwmfl_scalar.dll is missing and won't start. This is a dll that was included with 2013 but seems to be no longer included in 2014a (either in the program or in the compiler runtime distribution). If I link against 2013a it runs no problems. Why would it insist on an old DLL when I update to 2014a? I've changed all includes, libs, environment to 2014a and rebuilt after a clean. I have no explicit reference to libmwmfl_scalar.dll in my properties and have changed all folders to 2014a. I'm not linking to anything else that uses Matlab. This dll doesn't show up if I run dependency walker on the linked executable.

The settings are as in this property sheet from another post (Call MATLAB directly (multiple threading) in Visual Studio) which provides some relevant context.

<?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 - no I'm not using Mex files. This is the code that calls 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;
}

Here is my Path, with both 2013a and 2014a present. I've also tried removing 2013a, relaunching VS, rebuilding but it still looks for the old 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 Files (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\

Update: I tried creating a new solution and project in VS2013 and it works with ML2014a. So it must be something affecting my existing project or solution but it's very hard to track down since I have no indirect dependencies to Matlab and have set all paths to the 2014a version. My program uses external libs Boost, Intel MKL, Armadillo, Eigen, Quantlib. Totally stumped.

Update 2: I've checked and my program runs when linked against 2014a outside the Visual Studio environment. It is when I try to run it from VS for debugging purposes ("debug/start debugging" or "debug/start without debugging") that it wont' run because of the missing libmwmfl_scalar.dll. So for some reason VS insists on this to run the program when the program itself doesn't use it.

Community
  • 1
  • 1
Rod
  • 21
  • 3
  • No mex files, right? – Ben Voigt Oct 11 '14 at 00:13
  • @Rod: try re-registering MATLAB R2014a as COM server: http://www.mathworks.com/help/matlab/matlab_external/building-and-running-engine-applications-on-windows-operating-systems.html#bsqi0dh-2 (you need to run this with Admin privileges). Also, it would help if you check your `PATH` environment variable (just open a cmd.exe command prompt, run `echo %PATH%`, and post the output in your question) – Amro Oct 11 '14 at 03:43
  • Ben - no I'm not using Mex files. I've added the function that calls Matlab to my question. – Rod Oct 12 '14 at 04:31
  • Amro - thanks I tried re-registering 2014a as a COM server. The re-registering works but my program still looks for the old DLL. After re-registering 2014a and removing 2013a from the path, I expect Visual Studio shouldn't even know anything about 2013a but still looks for the 2013a DLL. I've added my path above. – Rod Oct 12 '14 at 04:31

0 Answers0