MEXFILE error, libmex.dylib not loaded

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
Walter Roberson el 4 de Mzo. de 2021
Which MacOS release are you using?
Luis Colon-Perez
Luis Colon-Perez el 4 de Mzo. de 2021
Mojave 10.14.6
Luis Colon-Perez
Luis Colon-Perez el 4 de Mzo. de 2021
Matlab 2019b

Iniciar sesión para comentar.

Respuestas (2)

John
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
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
Luis Colon-Perez el 5 de Mzo. de 2021
Thank you for the info. I tried your suggestion and it doesn't work. olddy it empty at since DYENV is empty. I created a .bashrc file (did not have one and added DYLD_LIBRARY_PATH=/path/to/imagemagick/library:${DYLD_LIBRARY_PATH} to it but it still not working. Do you have any idea how to find and edit the property list for MATLAB to include /Applications/MATLAB_R2019b.app/bin/maci64 on the DYLD_LIBRARY_PATH environment variable. I downloaded TextWrangler (now its BBEdit) which I have used before but not to edit the Matlab property list
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
Luis Colon-Perez el 5 de Mzo. de 2021
Thank you for your replies but if I add those two lines to info.plist then Matlab won't open and if I open it and change it after its already open, as one would expect then it doesn't work either. Would you think that erasing
<key>MATLAB_USE_USERWORK</key>
<string>1</string>
would work?
Walter Roberson
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
Luis Colon-Perez el 5 de Mzo. de 2021
Ok, thanks. I guess there's no work around to this. Appreciate the comments
Walter Roberson
Walter Roberson el 5 de Mzo. de 2021
The work-around is probably to copy libmex.dylib to /usr/lib/
Luis Colon-Perez
Luis Colon-Perez el 5 de Mzo. de 2021
I tried that before asking here. It wouldn't let me, most likely SIP on mac. I will try to find the .c file and compile it. I'll figure it out. thanks
Walter Roberson
Walter Roberson el 5 de Mzo. de 2021
I suspect you are using APFS... I guess you have to in Mojave.

Iniciar sesión para comentar.

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.

Preguntada:

el 4 de Mzo. de 2021

Editada:

el 14 de Abr. de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by