Interfacing a C++ library with Matlab
Show older comments
Hello,
I have a simple C++ library, comprised of a header (.h) and a source file (.cpp). It uses C++ strings, and if possible I would like to keep it that way (meaning not have to modify it to use C strings instead). The library was compiled using Visual Studio MSVC 142, and I am using Matlab R2022a. I want to use this library in Matlab, and be able to export it to some other machines.
I followed this guide to generate a Matlab interface .dll directly from Matlab : https://fr.mathworks.com/help/matlab/matlab_external/steps-to-publish-a-matlab-interface-to-a-c-library.html . I then followed this guide to make the libraryInterface.dll into a toolbox, which would be the most optimal way to distribute it the way I would want to : https://fr.mathworks.com/help/matlab/matlab_prog/create-and-share-custom-matlab-toolboxes.html .
Installing the toolbox worked instantly on my machine. I was able to call my functions using clib.libraryName.functionName in a Matlab script with no issue whatsoever, everything worked as intended. Then I proceeded to export the libraryInterface.dll and the exact same script I ran on my machine onto another PC, to test if it would work. This PC has no C++ compiler installed, and runs Matlab R2019b. I got an error on the first clib call :
Unable to resolve the name clib.libraryName.functionName.
The .dll is installed correctly, and included in the path.
Here are my questions : Should what I did have worked, and if so would you have any idea what went wrong ? Does the new PC needs a MSVC compiler ? Or an up-to-date version of Matlab ?
Accepted Answer
More Answers (0)
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!