Updating Linux runtime path in Matlab to load a C++ interface library does not work.

1 vue (au cours des 30 derniers jours)
Damien Laidin
Damien Laidin le 17 Fév 2021
Modifié(e) : Damien Laidin le 17 Fév 2021
Hello,
I have built a Matlab interface library to use some C++ code in Matlab. I am to the point where I want to call this library in Matlab. I followed all the Matlab documentation about interface library, in particular this one : https://uk.mathworks.com/help/matlab/matlab_external/call-functions-in-linux-version-of-interface-to-c-shared-library.html which explains how to proceed but without success.
Let's call my lib "myLib".
Whatever way I tried, doing
doc clib.myLib
never works out of the box. I have to first try to autocomplete a command calling the library to trigger Matlab to load it.
And to get to load the interface library in the first place I experienced 2 cases. Let's say the initial C++ library is located in "nativeLibFolder".
  • When setting the runtime path in Matlab with the folowing command
setenv('LD_LIBRARY_PATH', [char(nativeLibFolder), pathsep, getenv('LD_LIBRARY_PATH')]);
Matlab never manage to interface library.
  • When setting the runtime path in my terminal with the following command :
export LD_LIBRARY_PATH=nativeLibFolder:$LD_LIBRARY_PATH
and running matlab from the command line then I manage to get the interface library loaded by triggering the autocompletion on it.
What am I doing wrong in the case 1 when setting the runtime path in Matlab ?
Turns out it is apparently impossible to set LD_LIBRARY_PATH in Matlab. This has to be done in the shell terminal and forces to run Matlab from the terminal as well.
From a user experience side I don't find this to be very friendly. I am generating the path of my C++ library at runtime in my Matlab script and forcing people or myself to go get the location of the lib and update LD_LIBRARY_PATH manually isn't nice.
Also, this would be very nice if it was explicitely stated in the doc that LD_LIBRARY_PATH must be set in the operating system and before starting Matlab. The current documentation, even if it is Windows only (nothing says it only works on Windows), seems to says that it should be possible https://uk.mathworks.com/help/matlab/matlab_external/set-run-time-library-path-for-c-interface.html#mw_814f558d-95de-47a3-9dc8-ba6ed916fc88

Réponses (0)

Catégories

En savoir plus sur Use Prebuilt MATLAB Interface to C++ Library dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by