Error for using "clibgen" with the "Eigen" library (clibgen을 활용하여 Eigen 라이브러리를 사용하는 C++ 파일의 호출)

2 vues (au cours des 30 derniers jours)
Jaeyub Hyun
Jaeyub Hyun le 28 Avr 2022
Réponse apportée : Moksh le 28 Sep 2023
Hi,
I am a proejct scienist from UC San Deigo, US.
Actually, my collegue and I have been trying to import a single C++ code (.cpp with .h) into MATLAB via the "clibgen", and the code has a single class and also call a numerical library, so-called "Eigen" for matrix manipulations.
However, we could import the all of member functions/variables declared in the class in the C++ code only excepting for the "Eigen" library.
Looking at the warning message on the command window as the below image, the warning seems to be attributed to the fact that the "Eigen" library is the template class-based.
FYI, ultimately, we'd like to import our own C++ codes consisting of the multiple classes and numerical libraries (e.g., nlopt, glpk, etc.), once we figure out the whole process of importing the C++ code through a single C++ code.
Do you have any ideas on this issue?
Thank you.

Réponses (1)

Moksh
Moksh le 28 Sep 2023
Hi Jaeyub,
I understand you are facing some issues while trying to import a single C++ code file in MATLAB through “clipgen”.
Kindly refer to the following steps to address the issue of importing C++ code with the "Eigen" library into MATLAB using "clibgen":
Separate the C++ code into two parts: interface and implementation:
  • Create a header file (.h) containing the class declaration, member functions, and variables. Exclude any implementation details and dependencies on the "Eigen" library from this header file.
  • Create a source file (.cpp) that includes the header file and contains the implementation of the class, including the parts that use the "Eigen" library.
Create a wrapper class:
  • Write a new C++ class that acts as a wrapper for the original class, providing an interface that can be easily imported into MATLAB.
  • The wrapper class should include the header file of the original class and any necessary headers from the "Eigen" library.
  • Implement the wrapper class by forwarding the function calls to the original class and handling any necessary conversions between MATLAB and C++ data types.
Use "clibgen" to import the wrapper class:
  • Generate the interface file using "clibgen" for the wrapper class, which should now be free of any "Eigen" library dependencies.
  • Import the generated interface file into MATLAB using "clibgen" to create a MATLAB interface for the wrapper class. This will allow you to use the class and its functions in MATLAB.
To isolate the dependencies on the "Eigen" library from the code that needs to be imported into MATLAB, one can follow a two-step process: separating the interface and implementation and creating a wrapper class. The wrapper class acts as an intermediary, providing a bridge between MATLAB and the original C++ code. By using a wrapper class, you can overcome the limitations of "clibgen" when dealing with template classes and unsupported language constructs.
For more information about the “clipgen” function, please refer to the following documentation:
File exchange link for an example C++ wrapper class for MATLAB:
Hope this helps resolve the issue you are facing.
Best Regards,
Moksh Aggarwal

Community Treasure Hunt

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

Start Hunting!