Filter löschen
Filter löschen

unable to mex a dll library to matlab code.

2 Ansichten (letzte 30 Tage)
Kaushik
Kaushik am 8 Nov. 2012
i have the following simple code:
extern "C" __declspec(dllexport) double __cdecl MLtest(double arg1,double arg2)
{
return arg1+arg2;
}
i create a dll from it resulting in Test1.dll and Test1.lib.
Then i write a simple mex functions testML.c
include<mex.h>
#include<math.h>
#include<matrix.h>
#include<stdio.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double z =0.;
double *a = mxGetPr(prhs[0]);
double *b = mxGetPr(prhs[1]);
double *c = mxGetPr(prhs[2]);
*a = MLtest(*b,*c);
}
in matlab i mex it using:
mex testML.c Test1.lib
this result in testML.mex32 and testML.mex32.pdb files.
Finally i try to use the function as follows
xxx5=zeros(1);
xxx6=zeros(1);
xxx7=zeros(1);
xxx5(1) =2;
xxx6(1) =5;
testML(xxx7,xxx5,xxx6);
and i get en error message:
Invalid MEX-file 'C:\Work\testML\testML.mexw32': The specified module could
not be found.
I checked with dependency walker and se nothing missing (well wer.dll mpr.dll ieshims.dll is missing but those are delay load functions which dependency walker catches and should not cause problem). can someone help please.
  2 Kommentare
Walter Roberson
Walter Roberson am 8 Nov. 2012
You are missing the # of #include<mex.h> but perhaps that was just a copy-and-paste problem.
Kaushik
Kaushik am 8 Nov. 2012
i am not missing the "#". I have it in my original program. i missed it while copying. best

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Walter Roberson
Walter Roberson am 8 Nov. 2012
You declare MLtest rather than testML
  1 Kommentar
Kaushik
Kaushik am 8 Nov. 2012
do not think this is the issue , after your comment i changed as follows:
made the original function TestDLL
extern "C" __declspec(dllexport) double __cdecl TestDll(double arg1,double arg2)
changed the c file name to TestDll.c which now contains:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
double z =0.;
double *a = mxGetPr(prhs[0]);
double *b = mxGetPr(prhs[1]);
double *c = mxGetPr(prhs[2]);
*a = TestDll(*b,*c);
}
finally in the matlab code:
xxx5=zeros(1); xxx6=zeros(1); xxx7=zeros(1); xxx5(1) =2; xxx6(1) =5; TestDll(xxx7,xxx5,xxx6); xx8=9;
and i stll get the same error:
Invalid MEX-file 'C:\Work\AC QM - MOVE\AAA\v7_0_3\testML\TestDll.mexw32': The specified module could not be found.

Melden Sie sich an, um zu kommentieren.


Kaustubha Govind
Kaustubha Govind am 8 Nov. 2012
The error "The specified module could not be found." usually occurs when the MEX-file cannot find a dependency. In this case, your MEX-file needs Test1.dll, but is unable to find it. You either have not added it to the System path, or the DLL architecture does not match that of the MEX-file. For instance, your MATLAB appears to be 32-bit, so the DLL should also be 32-bit - perhaps it is 64-bit?
  3 Kommentare
James Tursa
James Tursa am 8 Nov. 2012
Can you try putting the Test1.dll file in the current directory you are executing the TestDll routine from?
Kaustubha Govind
Kaustubha Govind am 12 Nov. 2012
What James suggested should work. If you don't want to put the DLL in the same folder as the MEX-file, perhaps MATLAB is not picking up the right system PATH? Make sure that the paths returned by getenv('PATH') contain the folder containing the DLL.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by