How to correctly manage DLLs on Matlab path
34 ビュー (過去 30 日間)
古いコメントを表示
Nikita Visnevski
2019 年 7 月 17 日
編集済み: Nikita Visnevski
2019 年 10 月 23 日
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 件のコメント
採用された回答
Prashant Nirmal
2019 年 10 月 23 日
編集済み: Prashant Nirmal
2019 年 10 月 23 日
In case of Linux and Mac. See "-L" and "-l" flags in "mex" documentation
0 件のコメント
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!