How do I publish interface to shared C++ library that has nested library dependencies?

I am trying to use a C++ library through MATLAB, and I am following this documentation: 
The example works fine. But I failed on this particular case I have. I am trying to access API of a static library (For example “A.lib”), and that library itself depends on another dynamic library (Let’s call it “B.dll”). I got unresolved symbol error. And the mentioned symbol is in "B.lib". Is there a way to capture this dependency when generating the interface? 

 Accepted Answer

All the library dependencies need to be specified when generating the interface. For your example, since your static library depends on the shared library, you need to specify the “B.lib” in the “Libraries” name-value pair in “clibgen.generateLIbraryDefinition”. Please refer to the script below: 
Lib = [fullfile(pwd(), build_type, ["A.lib", "B.lib"])] ; 
clibgen.generateLibraryDefinition(Header,...  
"IncludePath", IncludePaths,...  
"Libraries", Lib,...  
"PackageName",  
"Demo",...  
"ReturnCArrays", false,...  
"Verbose", true); 
Also, please note that before calling the interface, you need to add the location of dependent shared libraries to system runtime path. This is not required for static library. As your interface depends on "B.dll", please add its location to runtime path. For detailed steps on this, please refer to the link below: 

More Answers (0)

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!