Error when importing dll and header files using loadlibraryfunction, about #include <vector>

8 次查看(过去 30 天)
demo:
/*if not(libisloaded('ST_MarkDemo_CPP'))
loadlibrary('HM_Comm','HM_HashuScan.h')
end
libfunctions('HM_HashuScan');*/
erro:
'E:\X64\ST_MarkDemo_CPP_V2.0\ST_MarkDemo_CPP\HM_HashuScan.h:2:18: fatal error: vector: No such
file or directory
#include <vector>
^
compilation terminated.
///The imported header file "HM_HashuScan.h" exists #include <vector> ;May be matlab can not compile how to solve?
Thanks in advance!

回答(1 个)

Abhishek Chakram
Abhishek Chakram 2024-4-23
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:
build(defFile)
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

类别

Help CenterFile Exchange 中查找有关 Deploy to C++ Applications Using MATLAB Data API (C++11) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by