Interfacing a C++ library with Matlab
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 ?
0 Commenti
Risposta accettata
Harsha
il 20 Ott 2022
Creating an interface from header and source CPP files and support for .dll compiled libraries were added to MATLAB from R2021a release.
When using an interface created in R2022a in an older release, the following error will be displayed.
“Invalid or incompatible interface library, possibly created in a newer version of MATLAB. Rebuild the interface library for the current version.”
As new options and parameters were added when generating the interface in R2022a, the generated interface will not work in the previous releases. However, the interfaces generated in older releases will work fine in the later releases.
Using up-to-date version of MATLAB will resolve this issue.
Check version History section in this link to know features added and supported in different versions of MATLAB. https://in.mathworks.com/help/matlab/ref/clibgen.generatelibrarydefinition.html
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Manage Products in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!