MEXFILE error, libmex.dylib not loaded
84 views (last 30 days)
Show older comments
I receive the following error as I try to run a function.
I then check the mex set-up in matlab and I get
MEX configured to use 'Xcode with Clang' for C language compilation.
I try to see find libmex.dylib and I can see it within Matlab contents but not anywhere else
then I type in the terminal the following command and I get that libmex doesn't exist.
otool -L libmex.dylib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: 'libmex.dylib': No such file or directory
I think it might be related to the @loader_path but not sure.
How can I make MATLAB use its libmex.dylib file in its contents?
3 Comments
Answers (2)
John
on 12 Apr 2023
Edited: Walter Roberson
on 14 Apr 2023
Having the same issue on MacOS 11.7.4 (and MacOS 13.0.1 but let's focus on the earlier version). Tried everything @Walter Roberson suggested above and nothing worked (like @Luis Colon-Perez I could not open Matlab after editing the Info.plist as suggested). Last thing I tried was physically moving the entirety of 'MATLAB_Compiler_Runtime/v84/bin/maci64' into my 'usr/local/lib' folder as a possible workaround since it contained the library files libmat.dylib and libmex.dylib that were not being found in Matlab. That helped Matlab find those dylib files, but still bugging out:
Anyone find a solution to these mex compilation errors?
UPDATE: Disabled SIP and they compiled. People dont' recommend this but I never found another alternative. https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection
0 Comments
Walter Roberson
on 4 Mar 2021
You might need to do
DYENV = 'DYLD_LIBRARY_PATH';
olddy = getenv(DYENV);
path_to_add = fullfile(matlabroot, 'bin', 'maci64');
if isempty(olddy)
newpath = path_to_add;
else
newpath = [olddy, ':', path_to_add];
end
setenv(DYENV, newpath)
Or you might need to edit the property list for MATLAB to include /Applications/MATLAB_R2019b.app/bin/maci64 on the DYLD_LIBRARY_PATH environment variable. See https://apple.stackexchange.com/questions/5278/how-do-i-edit-a-plist-file for more information on editing property lists. Someone mentions TextWrangler, which I do recommend.
However...
Your version of MacOS is recent enough that System Integrity Protection (SIP) might cause DYLD_LIBRARY_PATH to be ignored, especially if it has been set at the shell environment variable level. It might be more forgiving if you set it in the property list.
System Integrity Protection (SIP) was always documented as only applying to Apple supplied software, but in practice it has been found to apply to MATLAB as well :(
8 Comments
Walter Roberson
on 5 Mar 2021
I suspect you are using APFS... I guess you have to in Mojave.
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!