Hi wenxue,
It appears to me that you are facing trouble in importing dll and header files using “loadlibrary” function. The error you are encountering suggests that MATLAB is unable to locate the “<vector>” header file during the compilation of a C++ library. This issue typically arises because the “loadlibrary” function uses a C compiler that does not recognize C++ headers or namespaces.
The “<vector>” header is a part of the C++ Standard Library, and its absence indicates that the necessary C++ compilation context is not being used. Functions written in C++ must be declared as extern "C".
Since “loadlibrary” primarily supports C libraries, when dealing with C++ libraries, it is often more reliable to use MATLAB C++ shared library interface. This involves creating a C++ MEX file or using the “clibgen” package to generate a MATLAB interface to the C++ library.
1. Using “clibgen” : If you are using MATLAB R2019b or later, the “clibgen” package can be used to generate a MATLAB interface to C++ libraries. Here is a basic outline for the same:
- Generate the Interface Definition File:
clibgen.generateLibraryDefinition('path/to/HM_HashuScan.h');
Adjust the path to where your header file is located.
- Review and Edit the Definition File: After generating the definition file, review it for any potential issues or adjustments needed.
- Build the MATLAB Interface:
Replace “defile” with the path to your definition file.
- Use the Generated Interface: Once the interface is built, you can use the C++ functions directly in MATLAB.
2. Creating a MEX File
- Alternatively, you can wrap the C++ code that uses “<vector>” in a MEX file. This approach requires writing a wrapper code in C++ that interfaces with MATLAB and then compiling it with the “mex” command.
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram