How to correctly manage DLLs on Matlab path
31 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nikita Visnevski
le 17 Juil 2019
Modifié(e) : Nikita Visnevski
le 23 Oct 2019
On Windows, I am building a mex function "myFcn_mex" which links to a DLL "myLib.dll" via an import library "myLib.lib". I have the following directory structure:
%MY_PROJECT_BASE%\bin\win\x86_64
myLib.dll
myLib.lib
%MY_PROJECT_BASE%\src\include
myLib.h
%MY_PROJECT%\src\matlab
myFcn.m
My Matlab code looks as follows:
function myFcn
if ~coder.target('MATLAB')
projectBase = getenv('MY_PROJECT_BASE');
includePath = [projectBase filesep 'src' filesep 'include'];
libPath = [projectBase filesep 'bin' filesep 'win' filesep 'x86_64'];
libName = 'myLib.lib';
coder.ceval('myFcn');
coder.cinclude('myLib.h');
coder.updateBuildInfo('addIncludePaths',includePath);
coder.updateBuildInfo('addLinkObjects',libName,libPath,'',true,true);
else
myFcn_mex;
end
end
In Matlab I do this:
[Line 1] >> addpath([getenv('MY_PROJECT_BASE') filesep 'bin' filesep 'win' filesep 'x86_64']);
[Line 2] >> cd(getenv('MY_PROJECT'));
[Line 3] >> codegen myFcn
[Line 4] >> myFcn
So:
- DLL and LIB files live in a folder which has been succesfully added to Matlab path [Line 1]
- Folder where dll and lib files reside is not the same where I need to create my mex function [Line 2]
- Codegen command successfully runs and creates the file myFcn_mex.mexw64 in my working directory [Line 3]
- Calling the mex function [Line 4] results in error:
...
Missing dependent shared libraries:
'myLib.dll' required by
...
The function call suceeds if I copy the DLL locally:
>> !cp %MY_PROJECT_BASE%\bin\win\x86_64\myLib.dll .\
I quite clearly remember that in the past just adding the directory where dll file resides to the Matlab path used to work. It no longer seems to be the case. I either have to have this DLL in my current directory or on the OS path, which would require me to exit Matlab, change the OS Path environmant variable, and then restart Matlab.
Questions:
- Is there not another way of managing a DLL? I do not want to do either of the two options I described above.
- How different would be the way to do that with a myLib.so file on Linux or myLib.dylib on Mac?
Thanks in advance
0 commentaires
Réponse acceptée
Prashant Nirmal
le 23 Oct 2019
Modifié(e) : Prashant Nirmal
le 23 Oct 2019
In case of Linux and Mac. See "-L" and "-l" flags in "mex" documentation
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur MATLAB Coder 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!