MatlabEngine.startMatlab fails on MacOS due to hardened runtime

3 visualizaciones (últimos 30 días)
Jeff Mandel
Jeff Mandel el 16 de Mzo. de 2024
Respondida: Ayush el 28 de Mzo. de 2024
I am trying to run a Maven plugin I developed for calling mcc to compile some MATLAB routines with Compiler SDK. The Mojo works fine on my Linux box, but I tried it on several Macs today (both maci64 and maca64) and it fails. The problem is that the (relatively) new System Integrity Protection strips the DYLD_LIBRARY_PATH from the environment, and MatlabEngine.startMatlab dies without it.This has been discussed in Apple Developer Forum and in MathWorks Community Forum. While there are ways to build an App for MacOS with the relevant entitlements, this doesn't seem possible for command line tools. While I'm not sure Apple is completely right to strip DYLD_LIBRARY_PATH, not being able call MatlabEngine on a Mac is a problem that needs to be addressed.

Respuestas (1)

Ayush
Ayush el 28 de Mzo. de 2024
Hi Jeff,
Based on the description of your problem and referring to the Apple Developer Forum answer link provided, I can see that this issue is driven from the changes done in MacOS on a system level by the System Integrity Protection (SIP) protocols. Since changing the SIP settings or DYLD_LIBRARY_PATH on the macOS machine is not possible nor advisable, here are some possible workarounds for the same:
1. Using a wrapper script, you could first set the necessary environment variables such as “DYLD_LIBRARY_PATH” from a Bash script required for your Maven Plugin. This script could be run before the Java application for “MatlabEngine.startMatlab” to detect this variable and function properly. Here is an example code for your reference:
#!/bin/bash
# Set the DYLD_LIBRARY_PATH to include MATLAB libraries
export DYLD_LIBRARY_PATH=/path/to/matlab/libs:$DYLD_LIBRARY_PATH
# Execute your Maven plugin or Java application
java -jar your-maven-plugin.jar
2. Using the inbuilt java library path mechanism, there may be an alternative to the stripped DYLD_LIBRARY_PATH variable in the form of “Djava.library.path” system property to specify the location of native libraries of MATLAB Runtime. This is an indirect way to make the application look in alternate locations for the native libraries.
3. Lastly you can ensure that MathWorks is aware about such difficulties faced by its macOS customers and provide a more robust solution or workaround for their MATLAB Engine and Compiler SDK users. You can contact the support from this link and provide your feedback on the same: https://www.mathworks.com/support/contact_us.html?s_tid=bug2create
Hope this helps!

Categorías

Más información sobre Java Package Integration en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by