Invalid MEX-file Error in R2013b

I'm getting the following error:
Mex file entry point is missing.
Please check the (case-sensitive) spelling of mexFunction (for C MEX-files), or the (case-insensitive)spelling of MEXFUNCTION (for FORTRAN MEX-files).
Invalid MEX-file
'C:\Users\sadowsky\Documents\Visual_Studio_2010\Projects\ParamsTree\Debug\ParamsTree_MEX.mexw32':
The specified module could not be found.
From reading answers to similar questions, there seem to be two answers - neither of which work for me.
The first answer is to check the mexFunction syntax, file name, etc. I've done that a thousand times.
The second answer is to use Dependency Walker to identify missing dlls. Dependency Walker flags two missing dlls - libmx.dll and libmex.dll. I checked my system path - it is set to C:\MATLAB\R2013b\bin where the matlab.exe is. The missing dlls are in the subfolder win32, so I added the path C:\MATLAB\R2013b\bin\win32. Dependency Walker now finds the missing dlls, but something else is now missing, and the matlab still doesn't run.
Below is the Dependency Walker screen shot when I set the system path to C:\MATLAB\R2013b\bin
And here is the Dependency Walker screen shot when have both C:\MATLAB\R2013b\bin and C:\MATLAB\R2013b\bin\win32 set as system paths.

Answers (1)

Jan
Jan on 16 Feb 2014
The error message is unique and clear: Matlab cannot find the entry point function called "mexFunction". Please 1001 times, if this function is contained in the code.
Whap happens if you compile the function from Matlab using the mex command?

2 Comments

The file name is ParamsTree_MEX.cpp (the code is below) and the Visual Studio project name is ParamsTree_MEX and it produces "ParamsTree_MEX.mexw32". Notice (a) I copied the mexFunction signature directly from the mex.h file, (b) I'm using class_handle.hpp file provided by Oliver Woodford (as downloaded from Matlab Central), and (c) the mexFunction calls function compiled in a separate dll imported using ParamsTree_Import.hpp. Everything builds and tests nicely on the Visual Studio side.
I want to use Visual Studio so I can run use the VS debugger when the mexFunction is called. Again, I've done that painlessly in the past.
Also, I did
which -all ParamsTree_Mex
in the matlab command window, and it correctly displayed path to my ParamsTree_MEX.mexw32 function.
Here is the C code:
#include "mex.h"
#include "class_handle.hpp"
#include "ParamsTree_Import.hpp"
void mexFunction(
int nlhs, /* number of expected outputs */
mxArray *plhs[], /* array of pointers to output arguments */
int nrhs, /* number of inputs */
const mxArray *prhs[] /* array of pointers to input arguments */
){
char cmd[64];
if ( (nrhs < 1) || mxGetString(prhs[0], cmd, sizeof(cmd)) ) mexErrMsgTxt("Must be at least one input");
if ( strcmp("new",cmd) == 0 )
{
if ( (nlhs != 1) || (nrhs != 3) ) mexErrMsgTxt("nrhs and or nlhs error");
char path[256], file[256];
mxGetString( prhs[1], path, sizeof(path));
mxGetString( prhs[2], file, sizeof(file));
plhs[0] = convertPtr2Mat<ParamsTree::Node>( ParamsTree::Node::createParamsTree( path, file ) );
return;
}
else
{
/*
bla bla bla
*/
}
// Got here, so command not recognized
mexErrMsgTxt("Command not recognized.");
}
OK - I think I have it working. I had to write
void __declspec(dllexport) mexFunction(
in both the cpp and mex.h files. I don't know why I didn't think of trying that sooner. Still, it is less than elegant to have to edit the mex.h file.

Sign in to comment.

Categories

Products

Asked:

on 16 Feb 2014

Commented:

on 17 Feb 2014

Community Treasure Hunt

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

Start Hunting!