Warning about array when use loadlibrary function

조회 수: 6 (최근 30일)
Furkan Beyhan
Furkan Beyhan 2020년 3월 17일
답변: Guillaume 2020년 3월 17일
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.

답변 (1개)

Guillaume
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.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by