Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Error when m-file calls cpp-file

Asked by Elysi Cochin on 2 May 2013

I have a folder that implements the Bayesian Color Constancy, and it contains .m files and .cpp files. When some .m file calls a .cpp file, MATLAB yields: ??? Undefined function or method ‹The functions' name› for input arguments of type ‹double›. although I have everything in path.

Do i need to install something special in order to make MATLAB recognize this file?

0 Comments

Elysi Cochin

Tags

Products

No products are associated with this question.

2 Answers

Answer by José-Luis on 2 May 2013
Accepted answer

You cannot call directly cpp files from Matlab. You need to use mex to compile cpp file into a format that Matlab can understand.

 doc mex

Once it is compiled you can call it directly from Matlab. As it stands, what the error message is telling you is that there is no function with that name that Matlab understand. The file might very well be there, but it is not possible to read it.

3 Comments

Elysi Cochin on 2 May 2013

sir how to use mex to compile cpp file.... please do reply sir.... i dont know how to convert into mex file.... please do reply sir.... it would great help for me sir.....

José-Luis on 2 May 2013

Have you tried reading the documentation? Please type

 doc mex

in the command line.

In a perfect world, if everything is already set up right:

 mex your_file.cpp

should suffice, and produce a function your_file() that you can then call from Matlab.

Please accept an answer if it helps you.

Elysi Cochin on 2 May 2013

sir i didnt understand the document much...

the code i used is from the link http://people.kyb.tuebingen.mpg.de/pgehler/colour/index.html

and in that the bayesiancc contains the cpp files i'm working on...

in the a function logp = logp_X(X,logemp,lambda)

the mex file is called...

 n_k = mex_histc(X,nBins);

just before this line i added...

 mex mex_histc.cpp
 n_k = mex_histc(X,nBins);

but this i got error as

    Error mex_histc.cpp: 17  illegal statement termination 
    Error mex_histc.cpp: 17  skipping `unsigned' `int' 
    Error mex_histc.cpp: 17  undeclared identifier `nBins' 
    Error mex_histc.cpp: 18  illegal statement termination 
    Error mex_histc.cpp: 18  skipping `double' 
    Error mex_histc.cpp: 18  undeclared identifier `X' 
    Error mex_histc.cpp: 18  type error: pointer expected 
    Error mex_histc.cpp: 18  operands of = have illegal types `int' and `pointer to double' 
    Error mex_histc.cpp: 20  illegal statement termination 
    Error mex_histc.cpp: 20  skipping `unsigned' `int' 
    Error mex_histc.cpp: 20  undeclared identifier `npts' 
    Error mex_histc.cpp: 21  illegal statement termination 
    Error mex_histc.cpp: 21  skipping `unsigned' `int' 
    Error mex_histc.cpp: 21  undeclared identifier `ndims' 
    Error mex_histc.cpp: 43  illegal use of type name `mwSize' 
    Warning mex_histc.cpp: 43  Statement has no effect 
    Error mex_histc.cpp: 43  syntax error; found `dims' expecting `;' 
    Error mex_histc.cpp: 43  undeclared identifier `dims' 
    Error mex_histc.cpp: 43  type error: pointer expected 
    Warning mex_histc.cpp: 43  Statement has no effect 
    Error mex_histc.cpp: 44  type error: pointer expected 
    Error mex_histc.cpp: 45  type error: pointer expected 
    Error mex_histc.cpp: 47  too many errors 
      C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Compile of 'mex_histc.cpp' failed. 
    ??? Error using ==> mex at 221
    Unable to complete successfully.
    Error in ==> logp_X at 11
    mex mex_histc.cpp
    Error in ==> rosenberg at 158
        logp = logp_X(X,logemp,lambda);
    Error in ==> sample_run at 15
    Lrb = rosenberg(I,mask,logemp);

please can you tell me what i should do?? please do reply sir....

José-Luis
Answer by José-Luis on 2 May 2013

Are you using linux?

2 Comments

Elysi Cochin on 2 May 2013

no sir i'm using windows 7

José-Luis on 2 May 2013

Then you need to compile it. I looked at the download and a compiled linux version is provided. There is a Makefile provided to help with the dependencies or whatnot. You should probably contact the author for help if you want to do in Windows.

José-Luis

Contact us