Why do I receive a "Library not loaded: @rpath/lib​MatlabEngi​ne.dylib" error when running a MEX function on macOS 14 or 13 [Sonoma, Ventura]?

3 Ansichten (letzte 30 Tage)
I compiled a MATLAB function into a MEX function using  on my Intel processor macOS machine. However, when I run the MEX function, I get the following error:
Invalid MEX-file
'/this/is/a/path/foo_mex.maci64': dlopen(/this/is/a/path/foo_mex.maci64,0x0006): Library not loaded: @rpath/libMatlabEngine.dylib
However, I have been able to compile and run without issue on my ARM processor macOS machine or older macOS machines. How can I run my MEX function on my Intel processor macOS?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 8 Nov. 2023
This is a known bug in MATLAB Compiler on macOS 14 and 13 machines on MATLAB R2023b. 
As a current workaround:
1. Extract the files in the zip archive attached to the external bug report.
2. Save a backup file for the MEX options files being replaced here by copying the file: "matlabroot>/bin/maci64/mexopts/clang++_maci64.xml" and rename it as "clang++_maci64.xml_backup"
3. Copy file "clang++_maci64.xml" from the archive and place it in "matlabroot>/bin/maci64/mexopts/clang++_maci64.xml"
To validate the changes, please run the following in the MATLAB Command Window:
cd(matlabroot) 
cd extern/examples/cpp_mex 
mex arrayProduct.cpp 
result = arrayProduct(3, 3) 
Alternate workaround for MATLAB code workflows only:
As a workaround, you can add the following flag to your "ldflags" definition in your "build.ninja" file: "-rpath $matlabdir/extern/bin/maci64".
Afterward, be sure to rebuild your MEX function using the script in the build folder. Make sure to copy the MEX function to the original folder you generated code from.
You will need to perform this workaround each time you generate code.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by