How to call external C++ function from Matlab

6 vues (au cours des 30 derniers jours)
Cheng Lyu
Cheng Lyu le 3 Juin 2019
Modifié(e) : sjhstone le 18 Juil 2019
I'm trying to call an external C++ function from Matlab to make it run faster.
I tried "coder.ceval", and got ERROR "The coder.ceval function is not supported in MATLAB"
I then tried "mex foo.cpp", and got ERROR "xcrun: error: SDK "macosx10.14.4" cannot be located"
I'm using "MacOS Mojave 10.14.5"
Does anybody know how to call C++ function from Matlab? Thank you sooooo much! I'm already driven crazy by this. T_T

Réponses (2)

Sean de Wolski
Sean de Wolski le 3 Juin 2019
Starting in 19a, you can call C++ libraries directly in MATLAB: https://www.mathworks.com/help/releases/R2019a/matlab/call-cpp-library-functions.html

Bobbie WU
Bobbie WU le 20 Juin 2019
I came across the same issue. Apparently, the mex command cannot find the SDK. I think the reason is that the SDK version has too much details (i.e. the 10.14.4 version number is unnecessary.)
To allow matlab to correctly locate the SDK, try the following command
mex SDKVER= foo.cpp
This basically sets the SDK version to null. It worked for me, hope that helps.
  2 commentaires
sjhstone
sjhstone le 2 Juil 2019
Thanks for this easy fix! From my experience with MEX on Windows, some xml files must contain a specific SDK version target but it would a lot more complicated to modify the xml file that comes with MATLAB.
sjhstone
sjhstone le 18 Juil 2019
Modifié(e) : sjhstone le 18 Juil 2019
The xml files are located at
[matlabroot '/bin/maci64/mexopts']

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Compiler SDK dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by