MATLAB interface to C library: defineargument() doesn't define the 'length' argument if already mentioned as part of the pointer argument

11 ビュー (過去 30 日間)
Jerome Almon
Jerome Almon 2023 年 11 月 20 日
コメント済み: Liam 2025 年 11 月 4 日 12:58
Hello,
MATLAB Version: 9.13.0.2049777 (R2022b)
Operating System: Microsoft Windows 10 Enterprise Version 10.0 (Build 19045)
I am trying to call C function (in a shared object) from MATLAB following the documentation in 'MATLAB interface to C library'.
  1. I am able to generate the interface dll file successfully. For the function "void mean(float32_t *v, uint32_t len);", I modified the SHAPE parameter for the argument 'v' to 'len' as instructed in the documentation.
defineArgument(meanDefinition, "v", "clib.array.library.Float", "input", "len", "Description", "[in] v Pointer to input array"); % <MLTYPE> can be "clib.array.library.Float", or "single"
defineArgument(meanDefinition, "len", "uint32", "Description", "[in] len Number of elements in array");
After this, I built the interface file and it's successful as well. However, when I call the function from matlab like this, clib.library.mean(buffer, size), it throws an error as incorrect number of arguments. So when I print the summary of the interface file, I notice that the type of second argument 'len' is missing/not defined.
=> clib.library.mean(clib.array.library.Float)
But when I don't specify the SHAPE parameter of 'v' argument as 'len' but just as 1 (for the sake of debugging),
defineArgument(meanDefinition, "v", "clib.array.library.Float", "input", 1, "Description", "[in] v Pointer to input array"); % <MLTYPE> can be "clib.array.library", or "single"
and build it, the summary has the second argument defined.
=> clib.library.mean(clib.array.library.Float,uint32)
2. Also the argument “v” is supposed to be of direction “inputoutput”. Because the list of values it points to are modified by the function. So when I change to it, it throws the following error,
Error using clibgen.FunctionDefinition/defineArgument
Invalid direction specified for argument 'v'. Expected direction is 'input'
Thanks,
Jerome.
  2 件のコメント
Stefanie Schwarz
Stefanie Schwarz 2023 年 11 月 28 日
@Jerome Almon Moderator comment: Removed the MATLAB license number from the post.
Liam
Liam 2025 年 11 月 4 日 12:58
For point 2. Use lib.Pointer. (https://uk.mathworks.com/help/matlab/matlab_external/working-with-pointers.html). InputOutput would suggest your method returns the pointer which it doesn't.
For point 1. Would also appreciate information.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by