Generating C/C++ Code from M-Function include MEX-File
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi. Is it possible to generating C/C++ Code and Standalone-Application from a M-Function include MEX-File?
I try it like this.
function result = callfunction %#codegen
result = uint32(0);
result = Addi_mex(2,3); %call a mex-file
end
The MEX-Function is written in C++
#include "mex.h"
#include "mexhelper.h"
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
ULONG sum=0, value1=0,value2=0;
// check Inputs
...
// Convert input data to unsigned integer via Matlab-function
...
sum = value1+value2;
plhs[0] = mmCreateMxArray(sum);
}
And Build to "Addi_mex.mexw32" with "mex -g -D_WIN32_WINNT -I ..." (MVS2010)
In the Workspace it works fine, but if I try to generate code or Standalone-Application from the function "callfunction.m" I get an error:
>> coder -build coder.prj
??? Only MATLAB files are supported for code generation. Unsupported file extension 'mexw32' for 'C:/.../coder_add/Add_mex.mexw32'.
I use the Matlab Coder. Is it maybe possible with the Matlab Compiler? And is it also possible to use in the MEX-File some other lib`s or dll`s? (in workspace seems to do)
I hope someone can help me.
0 Kommentare
Akzeptierte Antwort
Mike Hosea
am 20 Sep. 2012
Bearbeitet: Mike Hosea
am 20 Sep. 2012
Add
coder.extrinsic('Addi_mex');
to the top of your MATLAB function, and I think it will work in MATLAB. Basically, the compiler is expecting to be given MATLAB code to compile, but when it goes to try to compile Addi_mex, it finds the binary mex file, which it can't handle. If you declare it extrinsic, the compiler never tries to compile Addi_mex, just sets up a call to it.
However, for standalone code generation, ALL inputs must be in MATLAB or C. The compiler cannot deconstruct a mex file and emit C code. For this you wouldn't use your MEX file, rather you'd write a C library that is used both by your MEX file and your coder project. Then from your MATLAB function you would call into this library using coder.ceval.
6 Kommentare
Mike Hosea
am 21 Sep. 2012
Bearbeitet: Mike Hosea
am 21 Sep. 2012
It's been a very long time since I created a mex file "from scratch", but it looks like the mex command doesn't know about the library. Did you supply a "-l myLib" ?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!