Reputation: 1103
macos high sierra 10.13.1 xcode 9.2 matlab 2017b
while running a program in mac matlab in 2017b version, I tried to run pmtk3 from this link and while running I got the following error while running second command
error:
'/Users/laxmikadariya/Documents/MATLAB/pmtk3-master/pmtksupportCopy/markSchmidt-9march2011/markSchmidt/minFunc/lbfgsC.mexmaci64':
dlopen(/Users/laxmikadariya/Documents/MATLAB/pmtk3-master/pmtksupportCopy/markSchmidt-9march2011/markSchmidt/minFunc/lbfgsC.mexmaci64,
6): Library not loaded: @loader_path/libmex.dylib
Referenced from:
/Users/laxmikadariya/Documents/MATLAB/pmtk3-master/pmtksupportCopy/markSchmidt-9march2011/markSchmidt/minFunc/lbfgsC.mexmaci64
Reason: image not found.
How can I solve this issue in matlab mac?
I tried to set DYLD_LIBRARY_PATH in .bash_profile as DYLD_LIBRARY_PATH='/Applications/MATLAB_R2017b.app/bin/maci64:/Applications/MATLAB_R2017b.app/sys/os/maci64'
this couldnot solve the problem
Upvotes: 5
Views: 10932
Reputation: 31
Having similar issue on MacOS 11.7.4 (also on a different MacOS 13.0.1 but would be happy to get either working). A number of solutions were suggested on a Matlab Answer but nothing has worked.
I can't tell if this is a permissions issue with compiling mex files in newer MacOS or if I'm missing some key step. Obviously I linked to Xcode via sudo xcode-select -switch /Applications/Xcode.app
from Terminal and ran mex -setup
from Matlab.
Since I kept getting errors about not finding libmex.dylib (and libmat.dylib) and those files exist in 'MATLAB_Compiler_Runtime/v84/bin/maci64' I went ahead and coped those to 'usr/local/lib' and added that folder to path. The system still found a way to bug out (screenshot from different computer but have replicated this on both machines):
Anyone have any ideas or gotten mex files to compile in Matlab on OS ≥11.0?
UPDATE: Disabled SIP and they compiled. People don't recommend this but I never found an alternative. https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection
Upvotes: 0
Reputation: 21
You have to add the libraries to your matlab startup script
/Applications/MATLAB_R2017b.app/bin/.matlab7rc.sh
.
Add
DYLD_LIBRARY_PATH="/Applications/MATLAB_R2017b.app/bin/maci64:/Applications/MATLAB_R2017b.app/sys/os/maci64"
Then startup matlab from the command line
/Applications/MATLAB_R2017b.app/bin/matlab
Upvotes: 0
Reputation: 60564
The lbfgsC.mexmaci64
file comes pre-compiled, and with a time-stamp from 2012. Many things have changed on MacOS since then... :)
In a terminal window, I tried:
$> otool -L lbfgsC.mexmaci64
lbfgsC.mexmaci64:
@loader_path/libmx.dylib (compatibility version 0.0.0, current version 0.0.0)
@loader_path/libmex.dylib (compatibility version 0.0.0, current version 0.0.0)
@loader_path/libmat.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
As you can see, it references MATLAB's libraries using @loader_path
, which is wrong. That should be @rpath
.
I tried recompiling the MEX-file, from the MATLAB command prompt:
>> cd pmtk3/pmtksupportCopy/markSchmidt-9march2011/markSchmidt/minFunc
>> mex -compatibleArrayDims lbfgsC.c
The -compatibleArrayDims
option is necessary because the code is very old, and uses int
for array sizes (32 bits), rather than mwSize
(64 bits).
In a terminal window I now see:
$> otool -L lbfgsC.mexmaci64
lbfgsC.mexmaci64:
@rpath/libmx.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)
This looks a lot better, it's using @rpath
as it should. The MEX-file now ran, meaning that the linker problem is solved.
There is another MEX-file in this same directory, it will have the same problem. You'll have to compile that one at the same time:
>> mex -compatibleArrayDims mcholC.c
Upvotes: 7