unable to mex a dll library to matlab code.
1 view (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 8 Nov 2012
You are missing the # of #include<mex.h> but perhaps that was just a copy-and-paste problem.
Answers (2)
Kaustubha Govind
on 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 Comments
James Tursa
on 8 Nov 2012
Can you try putting the Test1.dll file in the current directory you are executing the TestDll routine from?
Kaustubha Govind
on 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.
See Also
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!