Invalid MEX-file

Hi all together,

I have an issue running minimal_example_ocp.m on my Mac (M1) on MATLAB.
When executing it, after a while I get following error message:

....
MEX completed successfully.
compiling acados_mex_reset_pendulum.c
Building with 'Xcode with Clang'.
MEX completed successfully.
delete template...
done.
Invalid MEX-file
'/Users/tonicai/acados/examples/acados_matlab_octave/getting_started/c_generated_code/acados_mex_create_pendulum.mexmaca64':
dlopen(/Users/tonicai/acados/examples/acados_matlab_octave/getting_started/c_generated_code/acados_mex_create_pendulum.mexmaca64,
0x0006): Library not loaded: @rpath/libacados.dylib
  Referenced from: <369C6F70-169F-3103-9C6E-5B7EE1648BC1>
  /Users/tonicai/acados/examples/acados_matlab_octave/getting_started/c_generated_code/acados_mex_create_pendulum.mexmaca64
    Reason: tried: '/Applications/MATLAB_R2024a.app/bin/maca64/libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/./libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/../../sys/os/maca64/libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/./libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/../../sys/os/maca64/libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/../../runtime/maca64/libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/../../sys/java/jre/maca64/jre/lib/server/libacados.dylib' (no such file),
  '/Applications/MATLAB_R2024a.app/bin/maca64/../../sys/java/jre/maca64/jre/lib/libacados.dylib' (no such file)

Error in pendulum_mex_solver (line 48)
            obj.C_ocp = acados_mex_create_pendulum();

Error in AcadosOcpSolver (line 72)
            obj.t_ocp = mex_solver();

Error in minimal_example_ocp (line 109)
ocp_solver = AcadosOcpSolver(ocp);

I have already seen in other discussions that it might be an issue with DYLD_LIBRARY_PATH and I have edited env.sh accordingly.
I have also already copied/adjusted cmake to create the .dylib files in usr/local/lib.
As I am not very familiar with everything, I don’t know if it is an issue with MATLAB or with acados but as far as I can see in the error message, MATLAB is not even looking in usr/local/ or in the acados folder for the file.

getenv('DYLD_LIBRARY_PATH') returns

ans =

  0x0 empty char array

tho…

Does anyone know what the issue might be?

I have MATLAB R2024a installed.

Thanks in advance,
Toni

You can also Set the environment variable directly from Matlab if thats easier

https://de.mathworks.com/help/matlab/ref/setenv.html?requestedDomain=

I’ve tried setting that way already too, but it still doesn’t work. getenv('DYLD_LIBRARY_PATH') does return the right path but matlab still doesn’t look in that path when executing.