Matlab Coder - Create DLL

3 ビュー (過去 30 日間)
Christian
Christian 2015 年 2 月 26 日
編集済み: Ryan Livingston 2015 年 3 月 3 日
As an example here is a function, that I want to compiler through Matlab coder in a DLL:
function [C] = Test(A,B) %#codegen
C=A+B;
end
Compiling this function and loading the DLL with "loadlibrary" I can see the required calling convention using libfunctionsview as expected: Return Type Name Arguments double Test (double, double)
Instead, if I have a function with two outputs:
function [C,D] = Test(A,B) %#codegen
C=A+B; D=A-B;
end
The calling convention is the following:
Return Type Name Arguments [doublePtr, doublePtr] Test (double, double, doublePtr, doublePtr)
Why the two additional arguments "... doublePtr, doublePtr)"? I need to avoid this and have a calling convention like this: Return Type Name Arguments [double, double] Test (double, double)

採用された回答

Ryan Livingston
Ryan Livingston 2015 年 2 月 26 日
When arguments are passed by pointer, loadlibrary creates extra output arguments for them. The third bullet at:
describes this more.
MATLAB Coder will generate a C function with a signature like:
void Test(double A, double B, double *C, double *D);
where the arguments C and D hold the return values after the call. C does not support returning multiple arguments like MATLAB, so multiple return values must be accomplished by using output reference arguments.
If you are going to use the code in MATLAB, generating a MEX function would make calling the generated code simpler. The generated MEX would be invoked as any other MATLAB function.
You could also generate a MEX function that calls your generated DLL using coder.ceval. There is an example in the documentation that shows how to do this.
  4 件のコメント
Christian
Christian 2015 年 2 月 27 日
編集済み: Christian 2015 年 2 月 27 日
I changed the output to be a struct: function [result] = Test(A,B,name) %#codegen
C=A+B; D=A-B; result.C=C; result.D=D; name=name;
end
This works now. However, I need to pass to the function a character array, see above. Doing this the calling convention becomes: [int8Ptr, struct_TPtr] Test (double, double, int8Ptr, struct_TPtr)
What is the integer pointers int8Ptr? How do I pass the character array?
Ryan Livingston
Ryan Livingston 2015 年 3 月 3 日
編集済み: Ryan Livingston 2015 年 3 月 3 日
There is a section in the documentation:
that discusses this in a bit more detail. The main takeaways are to convert the MATLAB string to int8 (I'm not sure how one handles non-ASCII with loadlibrary) and NULL-terminate the string.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by