How to create a MEX file from a C++ function
Show older comments
Hello, I am currently working on a program that integrates C++, MATLAB, and a geochemical program. I am using the C++ code that they provided to act as a pipe between my main code, written in MATLAB and the geochemical program.
As of now, I have not been able to figure out how to compile the pipe, which I want to solely be a standalone function without a main(). I want it to act like any other MATLAB function. It takes in a few variables and then updates their values as it gets more information from the geochemical program.
So far, I have included:
#include "mex.h" #define printf mexPrintf
and
int main() { cout << "hello world" << endl; return 0; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if( main() ) mexErrMsgTxt("main returned non-zero value");
}
in my code. Obviously the int main doesn't make too much sense, but without it's presence I don't know what I should include within the void mexFunction.
Any and all suggestions will be greatly appreciated. Thank you in advance!
Answers (3)
James Tursa
on 6 Jul 2011
0 votes
Please post the interface to the C++ function you wish to include in the mex function. i.e., specify what the inputs and outputs are.
Ilya
on 7 Jul 2011
Ilya
on 22 Jul 2011
0 votes
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!