Mex & shared library
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello to everyone,
I'm a student and I'm not very expert in Matlab. I am writing a mex file (double.c) under Linux which should call a routine from a shared library (lidouble.so). How can I do that? Which command should I write to fulfill my purpose?
Thanks to everyone for your kind attention and my best regards,
Jason.
0 comentarios
Respuestas (4)
Titus Edelhofer
el 23 de En. de 2012
Hi,
usually it is sufficient to do the following: add an include statement for the library to your mex file, so that the compiler "knows" the functions. Second, when compiling your code with mex add the library using the switch "-l" (see doc).
Titus
0 comentarios
Kaustubha Govind
el 23 de En. de 2012
This is what you are doing:
y = mxGetPr(plhs[0]);
y = timestwo(x);
The function timestwo overwrites the input pointer 'x' with two times its value and returns it - effectively overwriting the pointer 'y' with the location of 'x'. Therefore the original memory that was allocated for the output remains untouched:
plhs[0] = mxCreateDoubleMatrix(mrows, ncols, mxREAL);
Try making it:
*y = *(timestwo(x));
So that the values are copied instead of the pointer getting overwritten. Does this fix the issue?
0 comentarios
jason beckell
el 23 de En. de 2012
1 comentario
Kaustubha Govind
el 23 de En. de 2012
Glad to be of help. Also, please note that my solution works only as long as the output is a scalar. In case of an array/matrix, you'll have to loop over the value returned by timestwo and copy it into y.
jason beckell
el 23 de En. de 2012
1 comentario
Walter Roberson
el 23 de En. de 2012
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Ver también
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!