How to correctly manage DLLs on Matlab path
34 次查看(过去 30 天)
显示 更早的评论
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!