Warning about array when use loadlibrary function
2 次查看(过去 30 天)
显示 更早的评论
Hi guys, when I try use shared library (when I used loadlibrary function), I get 'Warning: The data type 'cstring#6' used by structure PtrStruct does not exist. The structure may not be usable.' warning.
I get this error when struct has an array. I could not take arrays which is members of struct from C library to MATLAB. Here is related struct in C;
typedef struct
{
double a;
double b;
char *chrArray[6];
}
PtrStruct;
How can I solve this problem? Thanks.
0 个评论
回答(1 个)
Guillaume
2020-3-17
Note that you get a warning, not an error. However, the warning is correct in that it's not possible to fill that structure in matlab. You then get an error if you try something like:
cstr = libstruct('a', 1, 'b', 2, 'chrArray', repmat({'aaaa'}, 1 , 6));
which is valid according to the structure definition but matlab errors telling you that "Only Structure arrays of simple data types are supported".
A simple workaround would be to split your array of char pointers into its 6 individual elements resulting in 6 fields:
typedef struct
{
double a;
double b;
char *chrArray_1;
char *chrArray_2;
char *chrArray_3;
char *chrArray_4;
char *chrArray_5;
char *chrArray_6;
}
It's been a while since I coded in C, but I believe that since the fields are all going to be pointers they will be contiguous so have the same memory layout of the array, so from the point of view of the compiled dll the 2 structures are the same.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!