why am I getting the error "Invalid MEX-file", while the file is in the current folder?

875 Views Asked by At

This is my current folder:
enter image description here
and here is the gateway function written in the file mx_minimum_power.cpp:

#include <math.h>
#include <complex>
#include <iostream>
#include "mex.h"
#include "matrix.h"
#include "armaMex.hpp"

using std::complex;
using std::cout;
using std::endl;


/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    double *arraysizePtr = NULL;
    arraysizePtr = mxGetPr(prhs[9]);
    const int arraysize = (int)*arraysizePtr;
    const int matrixDimention = 3;
    float *inMatrixA11 = (float *)mxGetPr(prhs[0]);
    float *inMatrixA12_real = (float *)mxGetPr(prhs[1]);
    float *inMatrixA12_imag = (float *)mxGetPr(prhs[2]);
    float *inMatrixA13_real = (float *)mxGetPr(prhs[3]);
    float *inMatrixA13_imag = (float *)mxGetPr(prhs[4]);
    float *inMatrixA22 = (float *)mxGetPr(prhs[5]);
    float *inMatrixA23_real = (float *)mxGetPr(prhs[6]);
    float *inMatrixA23_imag = (float *)mxGetPr(prhs[7]);
    float *inMatrixA33 = (float *)mxGetPr(prhs[8]);
    Mat <complex<float>> A(matrixDimention, matrixDimention);
    Mat <complex<float>> EigenVectors(matrixDimention, matrixDimention);
    Col <float> Eigenvalues(matrixDimention);
    int i = 0;
    for (i = 0; i < arraysize; i++)
    {
        A.at(0, 0) = complex<float>(inMatrixA11[i],0);
        A.at(1, 1) = complex<float>(inMatrixA22[i],0);
        A.at(2, 2) = complex<float>(inMatrixA33[i], 0);
        A.at(0, 1) = complex<float>(inMatrixA12_real[i], inMatrixA12_imag[0]);
        A.at(1, 0) = complex<float>(inMatrixA12_real[i], -inMatrixA12_imag[0]);
        A.at(0, 2) = complex<float>(inMatrixA13_real[i], inMatrixA13_imag[0]);
        A.at(2, 0) = complex<float>(inMatrixA13_real[i], -inMatrixA13_imag[0]);
        A.at(1, 2) = complex<float>(inMatrixA23_real[i], inMatrixA23_imag[0]);
        A.at(2, 1) = complex<float>(inMatrixA23_real[i], -inMatrixA23_imag[0]);
        eig_sym(Eigenvalues, EigenVectors, A);
    }
}

I have build the mx_minimum_power.mexw64 file through the following code:

mex -g mx_minimum_power.cpp blas_win64_MT.lib lapack_win64_MT.lib
Building with 'Microsoft Visual C++ 2013 Professional'.
MEX completed successfully.  

and as you see all both of the files Arii2011_modified.m and mx_minimum_power.mexw64 are in the current directory.
but when I run the following function:

[Ps,Pd,Pv,ThetaMean,Variance] = Arii2011_Modified(MMA.Data.C11,MMA.Data.C12_imag,MMA.Data.C12_real,MMA.Data.C13_imag,MMA.Data.C13_real,MMA.Data.C22,MMA.Data.C23_imag,MMA.Data.C23_real,MMA.Data.C33);  

in the command window, I get the error:

Invalid MEX-file 'D:\thesis library.Data\ALOS-PALSAR 12x2\San Francisco L
12x2\mx_minimum_power.mexw64': The specified module could not be found.  

I guess the error is somehow related to armadillo, because if I convert lines 29-45 of the mx_minimum.cpp to comments and then rebuild the mx_minimum_power.mexw64, I will not get such error and the MEX file is recognized


This is what I have found through inspecting the mx_minimum_power.mexw64 file in dependency walker.

enter image description here

1

There are 1 best solutions below

0
On

I added the files blas_win64_MT.dll and lapack_win64_MT.dll to the current folder and the problem got fixed Thanks to the comment made by @suever