Effacer les filtres
Effacer les filtres

Warning about array when use loadlibrary function

7 vues (au cours des 30 derniers jours)
Furkan Beyhan
Furkan Beyhan le 17 Mar 2020
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];
How can I solve this problem? Thanks.

Réponses (1)

Guillaume le 17 Mar 2020
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.


En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by