[macOS ARM64, MATLAB 2023b] "env.sh has not been sourced!" error in minimal_example_ocp despite environment being set

Hi :wave:,

I am working with acados on macOS (Apple M3 Pro, arm64) using MATLAB R2023b and the MATLAB/Octave interface. My goal is to run the provided MATLAB examples (e.g. minimal_example_ocp) and later integrate the solver into a Simulink-based thermal system model for my thesis.

I managed to build acados from source with cmake … && make install, and the libraries libacados.dylib, libblasfeo.dylib, and libhpipm.dylib are present in ~/MATLAB_2023b/Repos/acados/lib. CasADi is working fine in MATLAB, and I verified that symbolic expressions and functions evaluate as expected. In addition, my startup.m sets the environment variables correctly: ACADOS_INSTALL_DIR points to the acados installation folder, and DYLD_LIBRARY_PATH includes the lib directory. MATLAB confirms this with getenv, so the environment is visible from inside MATLAB.

When I run minimal_example_ocp, MATLAB successfully compiles the MEX files with Clang (all show “MEX completed successfully”), and acados templates are rendered without errors. However, the script fails immediately with:

Error using check_acados_requirements
env.sh has not been sourced! Before executing this example, run: source env.sh

This happens consistently, even though the environment variables are set. If I bypass this check, I encounter the next issue:

Invalid MEX-file acados_mex_create_pendulum.mexmaca64:
dlopen(.../acados_mex_create_pendulum.mexmaca64, 0x0006): 
Library not loaded: @rpath/libacados.dylib
Reason: tried:
  /Applications/MATLAB_R2023b.app/bin/maca64/libacados.dylib (no such file)
 ...

So MATLAB still fails to find libacados.dylib at runtime, even though the file exists in ~/MATLAB_2023b/Repos/acados/lib.

I already tried several things: launching MATLAB from the terminal after source env.sh, rebuilding all MEX files from scratch, setting both DYLD_LIBRARY_PATH and LD_LIBRARY_PATH inside MATLAB, and even manually patching the MEX binaries with install_name_tool. None of these attempts solved the issue.

My questions are therefore: Where exactly is the env.sh that check_acados_requirements expects? I only see some inside the examples/ folders but no top-level version after build. What is the recommended way to make libacados.dylib visible to MATLAB on macOS ARM64? Do I need to adjust the rpath of the MEX files during build, or is there an additional step after make install that I am missing?

For context, here are my system details: macOS Sequoia 15.x on Apple M3 Pro (arm64), MATLAB R2023b (arm64 build), acados cloned from the main branch with all submodules, CMake 4.1.1, GNU Make 4.4.1, Xcode Clang 17, Python 3.11 installed via Homebrew, and CasADi 3.7.2.

Any help on how to properly source env.sh or configure the library loading for MATLAB on macOS ARM would be greatly appreciated. Thanks a lot in advance!

Best,
Dino

Hi,

on Linux, the workflow is:

  1. cd to example directory
  2. source env.sh
  3. start matlab from terminal.

For MacOS, I am not sure what is needed.
In the env.sh in step 2) should be adapted to use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH.
I am not sure if setting DYLD_LIBRARY_PATH from within Matlab works in the same way.
Sorry, I can’t give further recommendations for macOS :confused:

Best,
Jonathan

Hello, I’m using Acados in Matlab on M2 Macbook Air.
In my experience, acados works as Clang.
As Jonathan said, specify DYLD_LIBRARY_PATH as the environmental variable of your acados path and run matlab at the terminal to operate normally.
Otherwise, an error called an invalid mex file occurs.

If it doesn’t work out, please leave a reply and I will let you know more detailed methods.

2 Likes

Hi guys, I am running from terminal after sourceing env.sh, but inside Matlab only ACADOS_SOURCE_DIR is set, while DYLD_LIBRARY_PATH remains empty. I tried to look around for ways to fix this, but my Matlab seems to categorically refuse to set this. Anyone knows how to fix this issue? I am on an arm Mac