-2

I have been trying to compile some mex files in matlab. The file was compiling well but it was throwing the following error while i ran it.

Invalid MEX-file 'filename.mexw32': The specified procedure could not be found.

I have narrowed down the cause to a function push_back() used in the code. The code snippet is as follows.

typedef vector<node> node_list;

node_list q;...

node n;

n.id         = 0;

n.parent     = -1;


  n.is_leaf    = 0; // <- set to 1 if node symbol is a terminal

  n.rhs_index  = 0;

  n.symbol     = ctx.start_symbol;

  n.rule_index = 0; // <- set after computing argmax rule

  n.rhs_index  = 0;

  n.x          = start_x;

  n.y          = start_y;

  n.l          = start_l;

  n.ds         = 0;

  n.dx         = 0; // <- set if def rule

  n.dy         = 0; // <- set if def rule

  n.score      = start_score;

  n.loss       = 0; // <-- set if start symbol

  q.push_back(n);

The final line q.push_back(n); is causing the error.

I have included the header files

mex.h, vector, iostream and list

How can I solve this issue? Should I define the method push_back here in the code? If yes, how should I do it? I am a beginner in c++. Any help would be appreciated.

wakjah
  • 4,541
  • 1
  • 18
  • 23
tej mohan
  • 37
  • 2
  • So you're saying that the code compiles but when you try to call it from MATLAB, MATLAB fails to load the compiled binary? – wakjah Jan 02 '15 at 12:37
  • yes. I am getting the above mentioned error. – tej mohan Jan 02 '15 at 12:42
  • Sounds like either there's a dependency missing, or you're compiling for a different version of MATLAB than the one on which you're running. See http://stackoverflow.com/questions/15338427/error-invalid-mex-file-the-specified-module-could-not-be-found – wakjah Jan 02 '15 at 12:47
  • I did not use any additional libraries or files. there's just one cpp file. and I am using a 32 bit operating system, windows 7 and matlab r2012. I am using the same matlab version for both compiling and execution. – tej mohan Jan 02 '15 at 12:52
  • You don't have the proper VS runtimes installed, or the library that implements `node`. – chappjc Jan 02 '15 at 17:26

1 Answers1

0

Each mex file needs a entry point, which is a function called "mexFunction".

The name "mexFunction" and it's signature is fixed, same for all mex functions, but matlab will use filename to identify them.

AFAIK, you are not able to run mex in a script style.

Common practice is to write your code in as a C function, then call that C function in "mexFunction".

user3528438
  • 2,737
  • 2
  • 23
  • 42