How to auto generate wrapper for MatLab coder generated file?

1 次查看(过去 30 天)
I am looking for help in using the MatLab generated DLL into my application directly. I have created a simple function in MatLab:
function [RetVal] = CalculateSum(SingleDimArray)
RetVal = sum(SingleDimArray);
end
Then I used a MatLab coder to generate a C/C++ DLL, which generates binary with following syntax:
double CalculateSum(const emxArray_real_T * SingleDimArray);
My application is having different requirement for using a DLL so I have created another DLL to wrap the DLL generated from MatLab coder like:
extern "C" __declspec(dllexport) void MyCalculateSum(VARIANT* Input, double* RetVal)
{
//Fetch Input array
SAFEARRAY *pInputArray = *(Input->pparray);
long arraySize = pInputArray->rgsabound[0].cElements;
double *pData = (double *) pInputArray->pvData;
//Create Input Args - Wrapper for MatLab generated code
emxArray_real_T *MLInputArray = emxCreateWrapper_real_T(pData, 1, MySize);
//Call MatLab functions
*RetVal = CalculateSum(MLInputArray);
//Release the struct
emxFree_real_T(&MLInputArray);
}
Currently I am doing this manually. Is there any way to generate this wrapper code through MatLab coder itself? If so then I can use the binary generated by MatLab coder directly in my application. I explored the possibility of including the “Custom C Code for Generated Files” but the content that I need to feed is static. I would like to know is there any way to generate the wrapper code for all the functions which is compiled from MatLab coder. I am trying to explore the “Code Replacement Library” option but didn’t get good example. Please throw some light on this area.

回答(1 个)

Sally Al Khamees
Sally Al Khamees 2017-7-13
I do not think that there is a way to do this. You will probably have to do it manually.
See if the following link helps
it has some information on code replacement.
  1 个评论
Royi Avital
Royi Avital 2019-9-14
It was really nice if there was an option to generate a code which an its entry point use regular types of C.
Namely regular pointers of C to arrays instead of the types defined by MATLAB.
To the leats you could add an auxiliray function which its input is a regular array of C and a vector of its dimensions and a scalar of the number of dimensions and its ouptut is the types of Coder.
At the moment coder yield a code which isn't fun to integrate to other projects.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by