问题
I am running glmnet package on MATLAB 2019a in macOS 10.14.5. I have also installed Xcode in my laptop.
I got the error like the following:
Invalid MEX-file '/Users/Desktop/Research/Paper Code/glmnet/glmnetMex.mexmaci64' : dlopen(/Users/Desktop/Research/Paper Code/glmnet/glmnetMex.mexmaci64,
6): Library not loaded: @loader_path/libmex.dylib
Referenced from: /Users/Desktop/Research/Paper Code/glmnet/glmnetMex.mexmaci64
I have tried the code mex -setup
and got
MEX configured to use 'Xcode with Clang' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB variables with more than 2^32-1 elements.
In the near future you will be required to update your code to utilize the new API.
You can find more information about this at: http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
I've found some advice from mathworks specific to mex
but I am not sure whether this can solve my problem. I stopped here since I am not sure if I should follow this answer to delete something.
Any ideas?
回答1:
The glmnetMex
MEX file included with the Glmnet download looks busticated on newer versions of macOS because it was compiled on a much older version of macOS (OS X 10.8, according to their website), and the DLL library loading mechanism has changed since then. (It should be using @rpath
instead of @loader_path
.) You will need to rebuild the MEX file yourself, or contact the Glmnet maintainers and ask them to provide a new build.
To rebuild the MEX file:
- Set up Matlab with
mex -setup
to use a compiler that can compile Fortran MEX files. (I don't actually know how to do this.) - In Matlab,
cd
to theglmnet_matlab
directory,!rm glmnetMex.mexmaci64
, and then runmex glmnetMex.F
I would consider this a bug in the Glmnet distribution; I have reported it upstream to the Glmnet maintainers.
(I can reproduce this issue with a fresh download of Glmnet on my macOS 10.14.6 box running Matlab R2019a, too.)
Here's a similar problem with another Matlab library's pre-built MEX file: Library not loaded: @loader_path/libmex.dylib in matlab. Next time try Googling for various parts of your error message; searching for "Library not loaded: @loader_path/libmex.dylib" will pull up that question.
来源:https://stackoverflow.com/questions/57538141/invalid-glmnet-mex-file-in-matlab