MEXFILE error, libmex.dylib not loaded
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 4 de Mzo. de 2021
Which MacOS release are you using?
Luis Colon-Perez
el 4 de Mzo. de 2021
Luis Colon-Perez
el 4 de Mzo. de 2021
Respuestas (2)
John
el 12 de Abr. de 2023
Editada: Walter Roberson
el 14 de Abr. de 2023
1 voto
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
Walter Roberson
el 4 de Mzo. de 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 comentarios
Luis Colon-Perez
el 5 de Mzo. de 2021
Walter Roberson
el 5 de Mzo. de 2021
Using .bashrc is not going to help, as the shell is not invoked when you double-click to launch MATLAB.
Use BBEdit to open /Applications/MATLAB_R2019b.app/Contents/info.plist
Search for LSenvironment . In R2020b that is roughly 40% of the way through, around line 2400 -- the location will very likely be different for R2019b.
You should see a <dict> there that might look something like
<key>LSEnvironment</key>
<dict>
<key>MATLAB_USE_USERWORK</key>
<string>1</string>
</dict>
Add a LD_LIBRARY_PATH key:
<key>LSEnvironment</key>
<dict>
<key>MATLAB_USE_USERWORK</key>
<string>1</string>
<key>LD_LIBRARY_PATH</key>
<string>/Applications/MATLAB.R2019b//bin/maci64</key>
</dict>
Luis Colon-Perez
el 5 de Mzo. de 2021
Walter Roberson
el 5 de Mzo. de 2021
That will not help
https://www.mathworks.com/help/matlab/matlab_env/assign-userpath-as-the-startup-folder-on-unix-or-macintosh.html
Luis Colon-Perez
el 5 de Mzo. de 2021
Walter Roberson
el 5 de Mzo. de 2021
The work-around is probably to copy libmex.dylib to /usr/lib/
Luis Colon-Perez
el 5 de Mzo. de 2021
Walter Roberson
el 5 de Mzo. de 2021
I suspect you are using APFS... I guess you have to in Mojave.
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!