How to create a wrapper workaround for C++ Library Interface with limitations of type float**, float const ** (is snot supported Type)

9 views (last 30 days)
I have a third party C++ Library without source code and i want to create a Matlab C++ Interface with the clibgen.generateLibraryDefiniton function. The compiler (MingGW64 C++) throws the following warnings :
Warning: Some C++ language constructs in the files for generating interface file are not supported and not imported.
Did not add 'MyFunctions1' at MyLib.h:198.'float const * *' is not a supported type.
Did not add 'MyFunctions1' at MyLib.h:353.'float * *' is not a supported type.
Did not add 'Myfunctions3' at MyLib.h:1048.
  'FILETIME' is an alias of type '_FILETIME'. Type '_FILETIME' is from std namespace or system header and is not supported.
I've found that there are limitations of C/C++ Support (See: C++Limitations) for
  • ** pointers
  • std namespace and system header
The _FILETIME type is included in the windows.h and is therefore defined in a system header.
%% Definition of the functions in MyLib.h file of the library
%const Float **
DLLAPI int WINAPI MyFunctions1(HNDL handle, int descinfo, const float** version,...
const char** infostring, const char** commentstring);
%Float **
DLLAPI int WINAPI MyFunctions2(HNDL handle, const char** namelist, float** valuelist, unsigned int listlen);
% FILETIME*
DLLAPI int WINAPI Myfunctions3(HNDL handle,unsigned int fileidx,char * namebuf,unsigned int maxbufsize,...
FILETIME* pftLastWriteTime,DWORD* nFileSizeHigh,DWORD* nFileSizeLow);
I've found THIS Example with a workarounds and THIS post for workarounds of some limitations.
Because i have no experience in C++ programming i have no idea, how a wrapper function could look like for this special cases or if it is even possible to handle that issue.
I hope somebody can help out. Thanks a lot

Accepted Answer

Siraj
Siraj on 3 Dec 2023
Edited: Siraj on 4 Dec 2023
Hi!
It is my understanding that you have a third-party C++ library for which you don't have the source code, and you want to utilize certain functions from this library in MATLAB, you may want to create a MATLAB C++ interface using the "clibgen.generateLibraryDefinition" function. However, some library functions are not added to the MATLAB interface and cannot be directly called from MATLAB.
Given the situation, we might consider creating wrapper functions for those functions that are not added to the interface. A wrapper function essentially calls the function it is wrapping around. For example, in the provided code snippet, "readStudentsWrapper" essentially just calls the actual "readStudents" function without performing any additional operations.
%% wrapper function to access the function that accepts std::stack input
void readStudentsWrapper(const CStack<Student>& students) {
readStudents(students.getData());
}
If you refer to the following link, it will provide a clear understanding of how wrapper functions can help overcome the limitations of the MATLAB interface to C++ libraries.
In the "Preprocessor Directives" section of the page, you'll learn that the MATLAB interface to a C++ library does not support preprocessor directives.
So the following line
#define PI 3.1415
has no effect in the MATLAB interface for the "Area" library.
To address this, a new file called "WrapperPI.hpp" is created, with the first line including "Area.hpp". This effectively incorporates all the code from "Area.hpp" into "WrapperPI.hpp". As a result, "WrapperPI.hpp" also becomes aware of the "PI" variable and its value of 3.1415.
Consider the function present in "WrapperPI.hpp":
double getPI(){ %%Wrapper function retrieves the value of PI
return PI;
}
This function will return 3.1415. In MATLAB, if you need to use the value of "PI", you can directly invoke the "getPI()" function.
In the section "Class Objects in std Namespace" on the same link, a "Student" class is created with two defined functions: "readStudents" and "getStudents". The "readStudents" function takes an argument, which is an object of type "stack", while "getStudents" returns a value of type "stack". As the "stack" class is defined in the "std" namespace, the MATLAB interface to a C++ library does not include functions that use objects defined in the std namespace. Consequently, "readStudents" and "getStudents" are not included in the interface created for this library.
To address this, a new class "CStack" is created, mimicking the functioning of the stack but not within the "std" namespace. Subsequently, a file "StudentWrapper.hpp" is created, which defines "readStudentsWrapper" and "getStudentsWrapper" functions. Since both of these functions use objects of type "CStack" instead of "stack", they will be included in the MATLAB interface and can be directly called from MATLAB. Behind the scenes, these functions call their corresponding functions defined in the "Student" class.
Since I don’t have much context about the library that you are using and its purpose, it’s a bit difficult to suggest a wrapper for the functions that are not being added. I hope the above explanation gives you some directions to come up with your wrapper function.
In your specific case, if "MyFunctions1" and other functions are not added and cannot be called, consider creating a new "hpp" file and defining another functions that can be added to the MATLAB interface, which in turn calls "MyFunctions1" and other corresponding functions. This approach may help address the issue at hand.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!