clibgen: Multidimensional C++ arrays not supported?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I was handed some C++ source code and its libraries (.dll, .dll.a) and am currently trying to run it in MATLAB.
For this, I'm using clibgen as described here: https://de.mathworks.com/help/matlab/matlab_external/steps-to-publish-a-matlab-interface-to-a-c-library.html
However, the C++ class contains some 2D arrays, like
int someArray [3][3];
that cause problems.
I tried to break it down to a very simple example class test that is defined in the file test.h (source code at the end). Every time I run
headerfiles = "CppTests/test.h";
clibgen.generateLibraryDefinition(headerfiles, "Verbose", true)
to generate the library for use in MATLAB, I get the following warnings:
Warning: Some C++ language constructs in the files for generating interface file are not
supported and not imported.
Did not add member 'Arr2d' to class 'test' at test.h:13.
'int [3][3]' is not a supported type.
Did not add member 'Arr2dFloat' to class 'test' at test.h:14.
'float [3][3]' is not a supported type.
Using MinGW64 Compiler (C++) compiler.
Generated definition file definetest.mlx and data file 'testData.xml' contain definitions for 6 constructs supported by MATLAB.
Build using build(definetest).
Everything works fine for simple data types like int or float, or even for 1D arrays like
int someVector [3];
Is there a way to use 2D C++ arrays in a MATLAB library? Or am I making some other mistake that generates these errors?
Here's the C++ header file for test:
class test
{
private:
/* data */
public:
test(/* args */);
~test();
int intArr [3] = {};
float floatArr [3] = {};
double doubArr [3] = {};
int Arr2d [3][3] = {};
float Arr2dFloat [3][3];
};
test::test(/* args */)
{
}
test::~test()
{
1 comentario
Jacob Anderson
el 24 de Nov. de 2021
Hi @Maximilian Georg von Arnim, I am also having the same issue. Were you able to resolve this or find a workaround to pass a multi-dimensional array through clib?
Respuestas (1)
Soumya
el 13 de Ag. de 2025
I recently encountered a similar situation while working with the ‘clibgen’ interface and did some investigation. It turns out that certain C++ datatypes and language features, like multidimensional data member arrays, are currently not supported by MATLAB’s ‘clibgen’ interface.
To work around this issue, I followed the steps given below:
- Flatten in C++ – Convert a 2D array to 1D:
int Flat[9]; //Access as Flat[row * 3 + col]
- Use the flattened array with ‘clibgen’.
Please refer to the following official documentation from MathWorks for more information:
- Limitations to C/C++ Support: https://www.mathworks.com/help/matlab/matlab_external/limitations-to-cpp-support-in-matlab-cpp-library-interface.html
- C++ Interface workarounds for limitations: https://www.mathworks.com/matlabcentral/answers/1640000-c-interface-workarounds-for-limitations
I hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Build MATLAB Interface to C++ Library en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!